-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
65 lines (56 loc) · 1.62 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const passport = require("passport");
const { passportCallback, auth } = require("./utility/auth");
const LocalStrategy = require("passport-local").Strategy;
var cors = require('cors')
const PORT = process.env.PORT || 8080;
const {
createPost,
getScream,
comment,
likeScream,
unlikeScream,
deleteScream,
feed,
deleteComment,
} = require("./handlers/screams.js");
const {
uploadImage,
signup,
login,
getUser,
setNotificationsRead,
getAvatar,
broadcast,
} = require("./handlers/users.js");
app.use(cors({origin : 'http://localhost:3000'}));
app.use(bodyParser.json());
app.use(require("morgan")("dev"));
app.use(passport.initialize());
app.use(passport.session());
app.get("/scream/:screamId", getScream);
app.get("/feed", feed);
app.get("/scream/:screamId/like",auth, likeScream);
app.get("/user/:handle",getUser);
app.get("/avatar/:avatar",getAvatar);
app.delete("/scream/:screamId/unlike", auth,unlikeScream);
app.delete("/scream/:screamId/deletecomment", auth,deleteComment);
app.delete("/scream/:screamId/delete", auth,deleteScream);
app.post("/broadcast", broadcast);
app.post("/scream/:screamId/comment", auth,comment);
app.post("/scream",auth, createPost);
app.post("/avatar/upload", auth,uploadImage);
app.post("/signup", signup);
app.post("/login", login);
app.get("/notifications", setNotificationsRead);
passport.use(
new LocalStrategy(
{ usernameField: "email", passwordField: "password" },
passportCallback
)
);
app.listen(PORT, () => {
console.log("Listening on port ", PORT, "!");
});