1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-14 03:30:18 +00:00
musix-oss/node_modules/snekfetch/test/server.js
MatteZ02 5eb0264906 fix
2019-05-30 12:06:47 +03:00

42 lines
878 B
JavaScript

const http = require('http');
const ref = require.main === module;
const server = http.createServer((req, res) => {
if (!ref)
req.connection.unref();
switch (req.url) {
case '/invalid-json':
res.setHeader('Content-Type', 'application/json');
res.end('{ "a": 1');
break;
case '/form-urlencoded':
res.setHeader('Content-Type', 'application/x-www-form-urlencoded');
res.end('test=1&hello=world');
break;
case '/echo': {
let body = '';
req.on('data', (c) => { body += c; });
req.on('end', () => {
res.end(body);
});
break;
}
default:
res.end();
break;
}
});
server.on('connection', (socket) => {
if (!ref)
socket.unref();
});
server.listen(0);
exports.port = server.address().port;
if (ref)
console.log(exports.port); // eslint-disable-line no-console