-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (50 loc) · 1.24 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const
express = require('express'),
fun = require('funcy'),
_ = require('highland')
let matcher = (pattern, handler) => {
return [pattern, handler];
}
let route = (path, handler) => {
return matcher([path, fun.wildcard, fun.parameter], handler);
}
let catchall = (handler) => {
return route(fun.wildcard, handler)
}
let router = fun(
route('/', response => {
return [ response, { status: 200, body: 'Hello World!' } ]
}),
route('/foo', response => {
return [ response, { status: 418, body: 'BAR!' } ]
}),
catchall(response => {
return [ response, { status: 400 } ]
})
)
let responder = fun(
matcher([fun.parameter, {status: fun.parameter, body: fun.parameter}],
(response, status, body) => {
response.status(status).send(body)
}
),
matcher([fun.parameter, {status: fun.parameter}],
(response, status) => {
response.sendStatus(status)
}
)
)
let app = express()
let requests = (push, next) => {
app.get(/$/, (request, response) => {
push(undefined, [ request.path, request, response ])
next()
})
}
let server = app.listen(3000, () => {
console.log(`Listening on port ${server.address().port}`)
_(requests)
.map(router)
.each(responder)
})