-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (33 loc) · 889 Bytes
/
index.js
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
32
33
34
35
36
37
38
39
const express = require('express');
const {createLightship} = require('lightship');
const port = Number(process.env.port || 8000);
const lightshipPort = Number(process.env.port || 9000);
const app = express();
app.get('/', (request, response) => {
response.send(`
<html>
<head>
<title>Hello!</title>
</head>
<body>
<p style="color: green">Hello, World!</p>
</body>
</html>
`);
});
app.get('/error', (request, response) => {
response.status(500).send('Uh oh');
});
const lightship = createLightship({
port: lightshipPort,
});
const server = app.listen(port, () => {
console.log('Listening on', port);
lightship.signalReady();
console.log('Ready to serve traffic');
});
lightship.registerShutdownHandler(() => {
return new Promise((resolve, reject) => {
server.close((err) => err ? reject(err) : resolve());
});
});