-
Notifications
You must be signed in to change notification settings - Fork 269
/
server.js
42 lines (37 loc) · 1.19 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
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');
const mysql = require('mysql');
const server = express();
server.use(bodyParser.urlencoded({ extended: false }));
//the cores config
server.all('*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
if (req.method == 'OPTIONS') {
res.send(200);
/make the require of options turn back quickly/
} else {
next();
}
});
server.listen(3333, () => {
console.log("正在监听3333端口");
});
//deal (cookie,session)
(() => {
server.use(cookieParser());
let keyArr = [];
for (let i = 0; i < 100000; i++) {
keyArr[i] = "xsa_" + Math.random() * 100 + i;
}
server.use(cookieSession({
name: "hc",
keys: keyArr,
maxAge: 30 * 60 * 1000
}))
})();
//deal router
server.use('/', require('./route/index.js')());