-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
71 lines (52 loc) · 1.69 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const express = require("express");
const cors = require("cors");
const path = require('path');
const {engine,create} = require('express-handlebars')
const sessions = require('express-session')
const cookieParser = require('cookie-parser')
const hostname = "127.0.0.1"
const PORT = process.env.PORT || 3000;
const hbs = create({})
const app = express();
//middleware
app.use('/static',express.static('static'))
app.use(express.json());
app.use(express.urlencoded({extended:false}));
app.engine('handlebars', engine({ defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
app.set('views', './views');
hbs.handlebars.registerHelper('equals',(arg1,arg2,options) =>{
return (arg1 == arg2) ? options.fn(this) : options.inverse(this)
})
hbs.handlebars.registerHelper('date',(arg1,arg2) =>{
const moment = require('moment');
return moment(arg1).format(arg2);
})
app.use(cors());
app.use(cookieParser());
app.use(sessions({
name: 'ueisAuth',
secret: 'randompassword',
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
maxAge: 3600000,
secure: false,
}
}));
//routes
app.get('/',(req,res) => {
res.render('welcome',{layout:false})
})
app.use("/Admin",require("./routes/api/Admin"));
app.use("/Dashboard",require("./routes/api/Dashboard"));
app.use("/Auth",require("./routes/api/Auth"));
app.use("/identity",require("./routes/api/identity"));
app.use('/card',require("./routes/api/card"));
app.use('/service',require("./routes/api/service"));
app.use('/third',require("./routes/api/third"));
app.use('/test',require("./routes/api/Test"));
app.listen(PORT, hostname, () => {
console.log(`Server running at http://${hostname}:${PORT}/`);
});