-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (40 loc) · 1.3 KB
/
index.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
const express = require("express");
const path = require("path");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const morgan = require("morgan");
const cors = require("cors");
const helmet = require("helmet");
//import config
const config = require("./config");
//import router
const Router = require("./router");
//create app using express
const app = express();
//Connect to the MongoDB
mongoose.connect(config.MONGO_URI)
//Secure Express Apps
app.use(helmet())
//CORS Options
const corsOptions = {
origin: true,
credentials: true
};
app.use(cors(corsOptions));
//Parse the body request to json
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json());
//HTTP request logger with Morgan
app.use(morgan("dev"));
app.use('/', express.static(path.join(__dirname, './build')));
app.use('/homepage', express.static(path.join(__dirname, './build')));
app.use('/dashboard', express.static(path.join(__dirname, './build')));
app.use('/login', express.static(path.join(__dirname, './build')));
app.use('/signup', express.static(path.join(__dirname, './build')));
app.use('/payment', express.static(path.join(__dirname, './build')));
//Router
Router(app);
//Listen server to the specific PORT
app.listen(config.PORT, () => {
console.log(`listen port ${config.PORT}`)
})