forked from 111116/webosu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
37 lines (32 loc) · 944 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
37
const http = require('http');
const url = require('url');
const hostname = '127.0.0.1';
const postport = 4000;
const getport = 4001;
var a = [];
const postserver = http.createServer((req, res) => {
var q = url.parse(req.url, true).query;
q.ip = "Guest";
if (q.title || q.sid) {
a.push(q);
}
if (a.length > 16) {
a.shift();
}
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Access-Control-Allow-Origin', '*');
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}/`);
});