-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (39 loc) · 1.25 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
// npm install express, ejs, mongoose, body-parser
// use yarn to go fast
var bodyParser = require('body-parser');
const express = require('express');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
const cookieParser = require('cookie-parser');
dotenv.config();
const app = express();
app.set('view engine', 'ejs');
let connect_uri = process.env.MONGO_DB;
mongoose.connect(connect_uri,
{ useNewUrlParser: true},
() => {
console.log("DB Address --> " + connect_uri);
}
);
// Import Routes
const IndexRoute = require('./routes/index');
const AccountRoute = require('./routes/account');
const MenuRoute = require('./routes/menu');
const ApiRoute = require('./routes/api');
const AuthRoute = require('./routes/auth');
// Middlewares
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
// Route Middlewares
app.use('/', IndexRoute);
app.use('/account', AccountRoute);
app.use('/menu', MenuRoute);
app.use('/api', ApiRoute);
app.use('/auth', AuthRoute);
// set owr public directory
app.use(express.static('public'));
const port = process.env.PORT;
app.listen(port, () => {
console.log("Server is running.");
});