-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (31 loc) · 1 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
const express = require('express');
const path = require('path');
const compression = require('compression');
const helmet = require('helmet');
const connectDB = require('./src/models/config');
const errorHandler = require('./src/middlewares/error_handler');
require('dotenv').config();
const indexRouter = require('./src/routes/index');
const catalogRouter = require('./src/routes/catalog');
const notFoundRouter = require('./src/routes/not_found');
const app = express();
// MongoDB
(async () => {
await connectDB();
})();
// view engine setup
app.set('views', path.join(__dirname, 'src/views'));
app.set('view engine', 'pug');
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'src/public')));
app.use(helmet());
app.use(compression());
// Routes
app.use('/', indexRouter);
app.use('/catalog', catalogRouter);
app.use('*', notFoundRouter);
// error handler
app.use(errorHandler);
app.listen(process.env.PORT || 3000);
module.exports = app;