-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (27 loc) · 818 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
const { Observable } = require('rxjs')
const { makeRouterDriver } = require('cycle-express-driver')
const express = require('express')
const run = require('@cycle/rxjs-run').default
const app = express()
const router = express.Router()
function main({ router }) {
const mainHandler$ = router.get('/').map(({ id }) => {
return { id, send: 'This is an example of cycle.js driver for express application' }
})
const delayed$ = router.get('/123').flatMap(({ id }) => {
return new Promise((resolve) => {
setTimeout(() => { resolve({ id, send: 'ok' }) }, 1000)
})
})
return {
router: Observable.merge(
mainHandler$, delayed$
)
}
}
run(main, {
router: makeRouterDriver(router)
})
app.use(router).listen(3000, () => {
console.log('Listening on http://localhost:3000/')
})