-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
38 lines (29 loc) · 1.04 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
const express = require("express");
//initialise db object
const server = express();
const cookieParser = require("cookie-parser");
const staticHandler = express.static("public");
server.use(staticHandler);
const bodyParser = express.urlencoded({ extended: false });
server.use(bodyParser);
const home = require("./routes/home");
const signup = require("./routes/signup");
const login = require("./routes/login");
const newsfeed = require("./routes/newsfeed.js");
const errorpage = require("./routes/404");
// COOKIE_SECRET lives in .env to stop it ending up on GitHub
// it is used to sign cookies so we can trust them
server.use(cookieParser(process.env.COOKIE_SECRET));
// get
server.get("/", home.get);
server.get("/signup", signup.get);
server.get("/login", login.get);
server.get("/newsfeed", newsfeed.get);
// post
server.post("/newsfeed", newsfeed.post);
server.post("/signup", signup.post);
server.post("/login", login.post);
const PORT = process.env.PORT || 3333;
server.listen(PORT, () => {
console.log(`listening on http://localhost:${PORT}`);
});