-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
40 lines (31 loc) · 1.02 KB
/
index.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
const restify = require('restify'),
port = 10843;
var server = restify.createServer({
'name': 'api.hzy.pw',
'version': '1.0.0'
});
//http://restify.com/#bundled-plugins
server.use(restify.acceptParser(server.acceptable));
//server.use(restify.queryParser());
//server.use(restify.jsonp());
server.use(restify.bodyParser());
server.use(restify.gzipResponse());
server.use((req, res, next)=>{
res.header('Access-Control-Allow-Origin', '*');
res.charSet('utf-8');
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log(`[${new Date().toLocaleString()}]\t${ip}\t${req.url}`);
next();
});
//saying
server.get('/saying/v1/ciba', require('./saying/ciba').v1GET);
server.get('/saying/v1/one', require('./saying/one').v1GET);
//avatar
server.get('/avatar/v1/:size/:id', require('./avatar/jdenticon').v1GET);
//static files
server.get(/\/static\/.+/, restify.serveStatic({
directory: './static'
}));
//listen
server.listen(port);
console.log(`listening on ${port}...`);