-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
60 lines (48 loc) · 1.59 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
var express = require('express');
var bodyParser = require('body-parser');
const mongoose = require('mongoose');
mongoose.connect('mongodb://heroku_m6wr26dg:[email protected]:63500/heroku_m6wr26dg');
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-s1-angular-npristin.herokuapp.com");
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('/api/session/set/:name/:value',
setSession);
app.get('/api/session/get/:name',
getSession);
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 sectionService = require('./services/section.service.server');
sectionService(app);
var enrollmentService = require('./services/enrollment.service.server');
enrollmentService(app);
var port = process.env.PORT || 4000;
app.listen(port, "0.0.0.0", function() {
console.log("Listening on Port 4000");
});