-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
39 lines (33 loc) · 917 Bytes
/
example.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
'use strict'
const createHafas = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
const sqlite3 = require('sqlite3')
const sqliteStore = require('cached-hafas-client/stores/sqlite')
const withCaching = require('cached-hafas-client')
const createServer = require('.')
const SECOND = 1000
const BASE_URL = 'http://localhost:3000/'
const BBOX = {
north: 52.53,
west: 13.355,
south: 52.5,
east: 13.43
}
const transformReq = (ctx, req) => {
req.headers['user-agent'] = 'App/4.5.1 (iPhone; iOS 14.8.1; Scale/3.00)'
return req
}
const hafas = createHafas({
...vbbProfile,
transformReq,
}, 'overwritten-anyways')
const db = new sqlite3.Database('example-cache.sqlite')
const client = withCaching(hafas, sqliteStore(db), {
cachePeriods: {
trip: 60 * SECOND,
radar: 30 * SECOND,
stop: 60 * 60 * SECOND,
},
})
const server = createServer(BASE_URL, client, BBOX)
server.listen(3000)