Created
January 17, 2017 09:17
-
-
Save Morabaraba/fddd168798de959fba5cb97d69e90e0d to your computer and use it in GitHub Desktop.
Express based log server for Qici Engine http://docs.qiciengine.com/manual/Debug/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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