-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
37 lines (31 loc) · 907 Bytes
/
api.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
const http = require('http');
const url = require('url');
const hostname = '127.0.0.1';
const postport = 3000;
const getport = 3001;
var a = [];
const postserver = http.createServer((req, res) => {
var q = url.parse(req.url, true).query;
q.ip = req.headers["x-real-ip"];
if (q.title || q.sid) {
a.push(q);
}
if (a.length > 16) {
a.shift();
}
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end("");
});
const getserver = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.setHeader('Access-Control-Allow-Origin', '*');
res.end(JSON.stringify(a));
});
postserver.listen(postport, hostname, () => {
console.log(`Server running at http://${hostname}:${postport}/`);
});
getserver.listen(getport, hostname, () => {
console.log(`Server running at http://${hostname}:${getport}/`);
});