-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (40 loc) · 1.18 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
// Modules
const express = require('express');
const indexRoutes = require("./routes/index");
const authRoute = require('./routes/auth');
const accountRoute = require('./routes/account.route');
const entryRoute = require('./routes/entry.route');
const dotenv = require('dotenv');
const mongoose = require('mongoose');
// const verify = require('./routes/verifyToken');
// modules config
const app = express();
dotenv.config();
const port = process.env.PORT;
// DB connection
mongoose.connect(
process.env.DB_CONNECTION,
{useNewUrlParser: true,useUnifiedTopology: true },
() => console.log("Connected DB")
);
const middleware = (req,res,next)=>{
console.log(req.method +" "+req.url);
next();
}
app.use(middleware);
app.use(express.json());
app.use(express.static(__dirname + '/public'));
// Custom routes
app.use('/auth',authRoute);
app.use('/account',accountRoute);
app.use('/entry',entryRoute);
app.use("/index", indexRoutes);
app.get("/", (req, res) =>
res.sendFile(__dirname+"/views/index.html")
);
app.get("/home",(req, res) =>
res.sendFile(__dirname+"/views/home.html")
);
app.listen(port, () => {
console.log(`Server start on port : ${port}`);
});