-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·48 lines (36 loc) · 1.23 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env node
const uuid = require('uuid')
const http = require('http');
const workflowOne = require('./workflow-one')
const workflowTwo = require('./workflow-two')
const {storage} = require('./storage')
const hostname = '127.0.0.1';
const port = 3000;
const context = (req) => {
const requestUuid = uuid.v4()
console.log(`starting requst: ${requestUuid} at ${req.url}`)
return {uuid: requestUuid, url: req.url}
}
const server = http.createServer((req, res) => {
storage.run(context(req), async () => {
const paths = req.url.split('/')
const [,workflow, args] = paths
let data;
if (workflow === 'one') {
data = await workflowOne.run(args)
} else if (workflow === 'two') {
data = await workflowTwo.run(args)
} else {
data = `Hello World at ${req.url}`
}
console.log(`ending request: ${storage.getStore().uuid}`)
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end(data);
})
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
http.get('http://127.0.0.1:3000/one')
http.get('http://127.0.0.1:3000/two')