-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
62 lines (46 loc) · 1.36 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
const express = require('express');
const cors = require('cors');
const cookieSession = require('cookie-session');
const cookieParser = require('cookie-parser');
const connectDB = require('./db/connect');
const userRoutes = require('./routes/user');
const todoRoutes = require('./routes/todo');
const port = process.env.PORT || 4000;
require('dotenv').config();
const app = express();
app.use(cors());
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static('public'));
app.set('view engine', 'ejs');
app.use('/',userRoutes);
app.use('/',todoRoutes);
// create a session and store data in a cookie in client side
app.use(cookieSession({
name: 'session',
keys: process.env.SECRET,
httpOnly: true,
maxAge: 24 * 60 * 60 * 1000 ,
}));
// To render the public files
app.get('/public/script.js', (req, res) => {
res.setHeader('Content-Type', 'application/javascript');
});
app.get('/public/todo.css', (req, res) => {
res.setHeader('Content-Type', 'text/css');
});
app.get('/',(req,res)=>{
res.render('landingpage');
});
const start = async()=>{
try {
await connectDB(process.env.MONGO_URI);
app.listen(port,()=>{
console.log(`server is running on http://localhost:${port}`);
});
} catch (error) {
console.log(error);
}
};
start();