-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
79 lines (66 loc) · 2.09 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var express = require("express");
var bodyParser = require("body-parser");
const mongoose = require("mongoose");
require("dotenv").config({ path: "./.env" });
const PORT = process.env.PORT || 4000;
const CONNECTION_URI =
process.env.MONGODB_URI || "mongodb://localhost/webdev-summer1-2018";
mongoose.connect(CONNECTION_URI);
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(function(req, res, next) {
res.header(
"Access-Control-Allow-Origin",
"https://cs4550-zelp-angular.herokuapp.com"
);
res.header("Access-Control-Allow-Origin", "http://localhost:4200");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.header("Access-Control-Allow-Credentials", "true");
next();
});
var session = require("express-session");
app.use(
session({
resave: false,
saveUninitialized: true,
secret: "any string"
})
);
app.get("/", function(req, res) {
res.send("Zelp Node.js Back-end");
});
app.get("/api/session/set/:name/:value", setSession);
app.get("/api/session/get/:name", getSession);
// app.get('/api/session/get',
// getSessionAll);
// app.get('/api/session/reset',
// resetSession);
function setSession(req, res) {
var name = req.params["name"];
var value = req.params["value"];
req.session[name] = value;
res.send(req.session);
}
function getSession(req, res) {
var name = req.params["name"];
var value = req.session[name];
res.send(value);
}
var userService = require("./services/user.service.server");
userService(app);
var responseService = require("./services/response.service.server");
responseService(app);
var postService = require("./services/post.service.server");
postService(app);
var restaurantService = require("./services/restaurant.service.server");
restaurantService(app);
var yelpService = require("./services/yelp.service.server");
yelpService(app);
var favoriteService = require("./services/favorite.service.server");
favoriteService(app);
app.listen(PORT);