-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
66 lines (53 loc) · 1.41 KB
/
server.js
File metadata and controls
66 lines (53 loc) · 1.41 KB
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
var express = require('express');
const React = require('react');
const ReactDOM = require('react-dom');
var cookieParser = require('cookie-parser');
var app = express();
app.use(cookieParser());
app.use(express.static('public'));
app.get('/setcookie', function (req, res){
res.cookie('email','hierifer@hotmail.com',{maxAge:800000, httpOnly:true});
res.redirect('/test.html?email=hierifer@hotmail.com');
res.end();
});
app.get('/cookie', function (req, res){
res.write(req.cookies.email);
res.end();
});
app.get('/getcookie', function (req, res){
console.log(req.cookies.email);
var email_cookie = req.cookies.email;
if(email_cookie != ""){
res.send(JSON.stringify(email_cookie));
res.end();
return;
}else{
res.send(JSON.stringify("cookie error"));
}
res.end();
});
app.post('/post_gradelist', function (req, res){
console.log(req.headers);
if(req.body.secondParam){
console.log(req.body.email);
res.send(JSON.stringify("this"));
return;
}else{
console.log("invalid");
res.send(JSON.stringify("this"));
return;
}
});
// catch 404 and forward to error handler
app.use(function(req, res, next) {
res.write("404: NOT FOUND");
res.end();
var err = new Error('Not Found');
err.status = 404;
next(err);
});
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
});