-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (35 loc) · 1.4 KB
/
server.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
const express = require("express");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const home = require("./routes/home.js");
const posts = require("./routes/view-posts.js");
const add = require("./routes/add-post.js");
const signUp = require("./routes/sign-up.js");
const login = require("./routes/login.js");
const deletePost = require("./routes/delete-posts.js");
const auth = require("./auth.js");
const server = express();
const bodyHandler = express.urlencoded({ extended: false });
server.use(cookieParser(process.env.COOKIE_SECRET));
//server.use(cookieParser("asdfghjklertyuio"));
server.use(bodyParser.urlencoded({ extended: false }));
const staticHandler = express.static("public");
server.use(bodyHandler);
server.use(staticHandler);
server.get("/posts", posts.showPosts);
server.post("/add-post", add.addPost);
server.get("/", home.get);
server.get("/sign-up", signUp.get);
server.post("/sign-up", signUp.post);
server.get("/login", login.get);
server.post("/login", login.post);
server.get("*", (req, res) => {
res.send(`<h1>Page not found</h1>`, 404);
});
server.post("/delete-posts", deletePost.post);
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => console.log(`Listening on http://localhost:${PORT}`));
process.on("unhandledRejection", (error) => {
console.error(error);
process.exit(1);
});