-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathindex.ts
More file actions
29 lines (22 loc) · 691 Bytes
/
index.ts
File metadata and controls
29 lines (22 loc) · 691 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
import { createServer } from 'http';
import message from './message';
const server = createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write(message);
res.end('\n');
});
server.once('listening', () => {
const addressInfo = server.address() || 'unknown';
const address = typeof addressInfo == 'string' ?
addressInfo : `${addressInfo.address}:${addressInfo.port}`;
console.log(`Server listening on ${address}`);
console.log(message);
}).listen(0);
process.once('SIGTERM', () => {
if (server.listening) {
server.close();
}
process.exit(0);
});
process.once('beforeExit', () => console.log('exit'));
export default server;