-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapi.js
64 lines (58 loc) · 1.65 KB
/
api.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
62
63
64
import {createClient} from './index.js';
import {profile as dbProfile} from './p/db/index.js';
import {profile as dbnavProfile} from './p/dbnav/index.js';
import {createHafasRestApi as createApi} from 'hafas-rest-api';
import {loyaltyCardParser} from 'db-rest/lib/loyalty-cards.js';
import {parseBoolean, parseInteger} from 'hafas-rest-api/lib/parse.js';
// TODO product support for nearby etc?
const mapRouteParsers = (route, parsers) => {
if (!route.includes('journey')) {
return parsers;
}
return {
...parsers,
loyaltyCard: loyaltyCardParser,
firstClass: {
description: 'Search for first-class options?',
type: 'boolean',
default: 'false',
parse: parseBoolean,
},
age: {
description: 'Age of traveller',
type: 'integer',
defaultStr: '*adult*',
parse: parseInteger,
},
};
};
const config = {
hostname: process.env.HOSTNAME || 'localhost',
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
name: 'db-vendo-client',
description: 'db-vendo-client',
homepage: 'https://github.com/public-transport/db-vendo-client',
version: '6',
docsLink: 'https://github.com/public-transport/db-vendo-client',
openapiSpec: true,
logging: true,
aboutPage: true,
enrichStations: true,
etags: 'strong',
csp: 'default-src \'none\'; style-src \'self\' \'unsafe-inline\'; img-src https:',
mapRouteParsers,
};
const start = async () => {
const vendo = createClient(
process.env.DB_PROFILE == 'db' ? dbProfile : dbnavProfile,
process.env.USER_AGENT || 'link-to-your-project-or-email',
config,
);
const api = await createApi(vendo, config);
api.listen(config.port, (err) => {
if (err) {
console.error(err);
}
});
};
start();