-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (42 loc) · 1.38 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
52
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const path = require('path');
const bodyParser = require('body-parser');
const verifyToken = require('./routes/verifyToken');
const authRoute = require("./routes/auth");
const todoRoute = require("./routes/todo");
const cookieParser = require('cookie-parser');
const port = process.env.PORT || 3000
mongoose.connect(
"mongodb+srv://Ishaan:Mouse123@cluster0.o0tfn.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
{ useNewUrlParser: true },
() => {
console.log("connected to database");
}
);
// Middleware
app.use(express.json());
app.use(express.static('views'))
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.get("/home", (req, res) => {
res.sendFile("/views/index.html", {root:__dirname});
});
app.get("/register", (req,res) => {
res.sendFile(path.resolve("views/register.html"));
console.log(__dirname);
})
app.get("/login", (req,res) => {
res.sendFile(path.resolve("views/login.html"));
})
app.get('/logout',(req,res) => {
res.clearCookie("authToken").redirect("/home");
})
app.get('/todo',verifyToken,(req,res) => {
console.log("sendFile process started")
res.sendFile(path.resolve("views/todo.html"))
})
app.use("/api/user", authRoute);
app.use("/api/todo", todoRoute)
app.listen(port, () => console.log("server is running now"));