-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserverControl.js
More file actions
31 lines (29 loc) · 1010 Bytes
/
serverControl.js
File metadata and controls
31 lines (29 loc) · 1010 Bytes
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
import debug from 'debug';
import { disableFusible } from '../fusible.js';
const serverInformation = () => (request, response, next) => {
if (!request.methodMatch(['DELETE']) || request.pathName !== '/') {
return next();
}
request.catched = true;
debug('ezs:info')(`Create middleware 'serverControl' for ${request.method} ${request.pathName}`);
const input = [];
return request
.on('error', err => next(err))
.on('data', chunk => {
input.push(chunk);
})
.on('end', async () => {
try {
const body = Buffer.concat(input).toString();
const bodyParsed = JSON.parse(body);
await disableFusible(bodyParsed['x-request-id'] || bodyParsed['X-Request-ID']);
response.writeHead(202);
response.end();
next();
}
catch (e) {
next(e);
}
});
};
export default serverInformation;