Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Express based log server for Qici Engine http://docs.qiciengine.com/manual/Debug/index.html
// hacked from the code at https://github.com/qiciengine/qiciengine-server
var port = 8900;
var bodyParser = require('body-parser')
var express = require('express');
var app = express();
var http = require('http').Server(app);
// 监听端口重复事件以进行重试
http.on('error', function(e) {
console.error('端口监听失败:%s', e.code);
});
app.use(bodyParser.text());
// Add headers
// http://stackoverflow.com/a/18311469
app.use(function(req, res, next) {
// Website you wish to allow to connect
// * wildcard, do not use :P
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
router = express.Router();
app.use('/remoteLog', router);
// 客户端请求 post http://107.0.0.1:8900/remoteLog
router.post('/', function(req, res) {
var body = req.body;
console.log(body)
res.send("200 OK");
res.end();
});
http.listen(port, function() {
console.log('成功监听端口:%d', port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.