-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (33 loc) · 1.06 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const express = require('express');
const cors = require('cors');
const routes = require('./routes/index');
const compression = require('compression');
let app = express();
const { jwtStrategy } = require('./config/passport.js');
const helmet = require('helmet');
const passport = require('passport');
app.use(helmet());
app.use(express.json());
// parse urlencoded request body
app.use(express.urlencoded({ extended: true }));
// gzip compression
app.use(compression());
app.use(cors());
app.get('/', (req, res) => {
res.status(200).json({
message: 'Welcome to the Node Express Mongoose API!',
version: '1.0.0',
description:
'This API serves as the backend for the Node Express Mongoose Starter project. It is built with Node, Express, MongoDB, Mongoose.',
author: 'Pratiyush',
repository: '',
documentation: '',
});
});
passport.use(jwtStrategy);
app.use('/v1', routes);
// send back a 404 error for any unknown api request
app.use((req, res, next) => {
next(new ApiError(httpStatus.NOT_FOUND, 'Not found'));
});
module.exports = app;