-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (32 loc) · 1.02 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
require("dotenv").config()
const express = require('express');
const path = require('path');
const mongoose = require("mongoose");
const cookiePaser = require("cookie-parser");
const {
checkForAuthenticationCookie,
} = require("./middlewares/authentication");
const userRoute = require("./routes/user");
const app = express();
const PORT = process.env.PORT || 3000;
mongoose
.connect(process.env.MONGO_URL)
.then((e) => console.log("MongoDB Connected"));
// Set view engine to EJSs
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.urlencoded({ extended: false }));
app.use(cookiePaser());
app.use(checkForAuthenticationCookie("token"));
// Serve static files from the "public" directory
app.use(express.static(path.join(__dirname, 'public')));
// Route to render the EJS template
app.get('/', (req, res) => {
res.render('home',{
user: req.user
});
});
app.use("/user", userRoute);
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});