-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (33 loc) · 1.21 KB
/
index.js
File metadata and controls
36 lines (33 loc) · 1.21 KB
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 express = require('express');
const app = express();
var bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: false}))
const os = require('os');
const {getData} = require('./api');
const {buildPostData,buildLocalData} = require('./app');
const e = require("express");
app.use(express.static("./"));
app.post('/api/post', function (req, res) {
// res.setHeader('Content-Type', 'text/plain;charset=utf8');
res.setHeader('Content-Type', 'application/json');
// console.log(JSON.stringify(req.body))
let body = req.body;
if (req.body.type === 'local') {
let data = buildLocalData(req.body);
console.log(new Date().toLocaleString()+'----'+JSON.stringify(data));
res.end(JSON.stringify(data.data));
} else if (req.body.type === 'net') {
let data = buildPostData(req.headers,req.body);
console.log(`buildPostData`,data);
getData(data).then((rev)=>{
// console.log(rev);
res.end(rev)
})
}
})
const server = app.listen(88, function (req, res, next) {
let host = server.address().address
let port = server.address().port
console.log("http://%s:%s", host, port)
})