-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (46 loc) · 1.6 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
45
46
47
48
49
50
51
52
require('dotenv').config({ path: './w3s-dynamic-storage/.env' });
const path = require('path');
const express = require('express');
const flash = require('connect-flash');
const helmet = require('helmet');
const compression = require('compression');
const favicon = require('serve-favicon');
const morgan = require('morgan')
const errorController = require('./controllers/error');
const adminRoutes = require('./routes/admin');
const shopRoutes = require('./routes/shop');
const authRoutes = require('./routes/auth');
const attachUserInfo = require('./middleware/attachUserInfo');
const sessionProvider = require('./middleware/sessionHandler');
const dbAdapter = require('./database');
const port = 3000;
const app = express();
const uploadsPath = path.join(__dirname, 'w3s-dynamic-storage/uploads');
app.set('view engine', 'ejs');
app.set('views', 'views');
app.use(morgan('tiny'));
app.use(helmet.hidePoweredBy({ setTo: 'X-Frame-Options' }));
app.use(compression());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(uploadsPath));
app.use(sessionProvider);
app.use(flash());
app.use(favicon(path.join(__dirname, 'public', 'images', 'favicon.ico')));
app.use(attachUserInfo);
// App routes
app.use('/admin', adminRoutes);
app.use(shopRoutes);
app.use(authRoutes);
// Error handler
app.get('/500', errorController.get500);
app.use(errorController.get404);
app.use(errorController.get500);
dbAdapter.initialize()
.then(() => {
app.listen(port);
console.log(`server listening at ${port}`)
})
.catch((err) => {
console.log(err);
});