-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
59 lines (49 loc) · 1.41 KB
/
main.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
53
54
55
56
57
58
59
//dependencies
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const settings = require('./app/settings');
const session = require('express-session');
const flash = require('connect-flash');
//import local module
const publicRouter = require('./router/public');
const authRouter = require('./router/auth');
const adminRouter = require('./router/admin');
const apiRouter = require('./router/api');
const token = require('./middleware/token');
//express middleware start
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(session({
secret: 'secret',
resave: true,
saveUninitialized: true
}));
app.use(flash());
app.use(express.static(path.join(__dirname, 'public')))
app.use(cookieParser(settings.cookie_screet))
app.set('view engine', "ejs")
app.locals = {
date: (new Date()),
}
app.use(function(req, res, next) {
const messages = req.flash('messages');
if(messages){
res.locals.messages = messages;
}
next()
})
//routeing setup
app.use('/api', token , apiRouter )
app.use(publicRouter)
app.use(authRouter)
app.use('/admin',adminRouter)
//error handlers
// app.use(notFoundHandler);
// app.use(errorHandler);
//404 not found handler
//application listeners
app.listen(settings.port, function () {
console.log('Local server running at http://localhost:' + settings.port);
})