mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-21 05:43:59 -07:00
HTTP test code.
This commit is contained in:
parent
0034efafe4
commit
c6a918d996
4 changed files with 293 additions and 0 deletions
48
tests/http/server.js
Normal file
48
tests/http/server.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
// ---------------------------------------------------------------------------
|
||||
// Customizable parameters:
|
||||
|
||||
var SERVER_PORT = 18080;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
|
||||
app.use(function(req,res,next) {
|
||||
req.rawBody = '';
|
||||
req.on('data', function(chunk) { req.rawBody += chunk.toString(); });
|
||||
req.on('end', function() { return next(); });
|
||||
});
|
||||
|
||||
var knownAgents = {};
|
||||
|
||||
app.get('/:agentId',function(req,res) {
|
||||
var agentId = req.params.agentId;
|
||||
if ((!agentId)||(agentId.length !== 32))
|
||||
return res.status(404).send('');
|
||||
knownAgents[agentId] = Date.now();
|
||||
return res.status(200).send(JSON.stringify(Object.keys(knownAgents)));
|
||||
});
|
||||
|
||||
app.post('/:agentId',function(req,res) {
|
||||
var agentId = req.params.agentId;
|
||||
if ((!agentId)||(agentId.length !== 32))
|
||||
return res.status(404).send('');
|
||||
var resultData = null;
|
||||
try {
|
||||
resultData = JSON.parse(req.rawBody);
|
||||
} catch (e) {
|
||||
resultData = req.rawBody;
|
||||
}
|
||||
result = {
|
||||
agentId: agentId,
|
||||
result: resultData
|
||||
};
|
||||
console.log(result);
|
||||
return res.status(200).send('');
|
||||
});
|
||||
|
||||
var expressServer = app.listen(SERVER_PORT,function () {
|
||||
console.log('LISTENING ON '+SERVER_PORT);
|
||||
console.log('');
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue