-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
test-server.js
37 lines (28 loc) · 894 Bytes
/
test-server.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
const express = require('express')
const app = express()
const port = 3000
// console log every request sent
app.use((req, res, next) => {
console.log(`[REQ] - ${req.method} ${req.url}`)
next()
});
app.get('/return/:status/:time', async (req, res) => {
const statusCode = parseInt(req.params.status);
const returnString =`Hello status ${statusCode} after ${req.params.time}ms !`
console.log(`[RES] - ${statusCode} ${returnString}`)
await new Promise(resolve => setTimeout(resolve, req.params.time));
return res.status(statusCode).send(returnString)
});
app.get('/', (req, res) => {
console.log("[RES] - Hello World!")
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
// app.ws('/ws', function(ws, req) {
// ws.on('message', function(msg) {
// console.log(msg);
// ws.send(msg);
// });
// });