-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
54 lines (47 loc) · 1.83 KB
/
main.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
/**
* Created by lingxue on 2017/2/22.
*/
var restify = require('restify');
(function main() {
var server = restify.createServer({
name: 'LOG_DEV',
version: '0.0.1'
});
server.pre(restify.pre.sanitizePath());
server.pre(restify.pre.userAgentConnection());
server.use(restify.throttle({
burst: 100,
rate: 50,
ip: true
}));
restify.CORS.ALLOW_HEADERS.push('Access-Control-Allow-Origin');
restify.CORS.ALLOW_HEADERS.push("Access-Control-Allow-Methods", "GET");
restify.CORS.ALLOW_HEADERS.push("Access-Control-Allow-Methods", "POST");
restify.CORS.ALLOW_HEADERS.push("Access-Control-Allow-Methods", "PUT");
restify.CORS.ALLOW_HEADERS.push("Access-Control-Allow-Methods", "DELETE");
restify.CORS.ALLOW_HEADERS.push("Access-Control-Allow-Headers", "x-requested-with,content-type");
server.use(restify.CORS());
server.use(restify.bodyParser({uploadDir: __dirname + '/../uploads/'}));
server.use(restify.acceptParser(server.acceptable));
server.use(restify.dateParser());
server.use(restify.authorizationParser());
server.use(restify.queryParser());
server.use(restify.gzipResponse());
var STATIS_FILE_RE = /\.(css|js|jpe?g|png|gif|less|eot|svg|bmp|tiff|ttf|otf|woff|pdf|ico|json|wav|ogg|mp3?|xml|woff2|map|apk|mp4?)$/i;
server.get(STATIS_FILE_RE, restify.serveStatic({directory: './web', default: 'index.html', maxAge: 0}));
server.get(/\.html$/i, restify.serveStatic({
directory: './web',
maxAge: 0
}));
server.get(/\.html\?/i, restify.serveStatic({
directory: './web',
maxAge: 0
}));
server.listen(9000, function onListening() {
server.get('/', restify.serveStatic({
directory: './web',
default: 'index.html',
maxAge: 0
}));
});
})();