db-vendo-client/api.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-12-08 21:42:57 +00:00
import {createClient} from './index.js';
import {profile as dbProfile} from './p/db/index.js';
import {profile as dbnavProfile} from './p/dbnav/index.js';
2025-02-13 19:41:46 +00:00
import {profile as dbwebProfile} from './p/dbweb/index.js';
import {mapRouteParsers} from './lib/api-parsers.js';
2024-12-08 21:42:57 +00:00
import {createHafasRestApi as createApi} from 'hafas-rest-api';
2024-12-07 16:16:31 +00:00
const config = {
hostname: process.env.HOSTNAME || 'localhost',
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
2024-12-08 21:42:57 +00:00
name: 'db-vendo-client',
description: 'db-vendo-client',
homepage: 'https://github.com/public-transport/db-vendo-client',
2025-01-10 18:59:32 +00:00
version: '6',
2024-12-07 16:16:31 +00:00
docsLink: 'https://github.com/public-transport/db-vendo-client',
openapiSpec: true,
logging: true,
aboutPage: true,
2024-12-18 00:08:52 +00:00
enrichStations: true,
2024-12-07 16:16:31 +00:00
etags: 'strong',
2024-12-18 00:10:59 +00:00
csp: 'default-src \'none\'; style-src \'self\' \'unsafe-inline\'; img-src https:',
mapRouteParsers,
2024-12-08 21:42:57 +00:00
};
2024-12-07 16:16:31 +00:00
2025-02-13 19:41:46 +00:00
const profiles = {
db: dbProfile,
dbnav: dbnavProfile,
dbweb: dbwebProfile,
};
2024-12-08 21:42:57 +00:00
const start = async () => {
const vendo = createClient(
2025-02-13 19:41:46 +00:00
profiles[process.env.DB_PROFILE] || dbnavProfile,
process.env.USER_AGENT || 'link-to-your-project-or-email',
config,
);
2024-12-08 21:42:57 +00:00
const api = await createApi(vendo, config);
2024-12-07 16:16:31 +00:00
2024-12-08 21:42:57 +00:00
api.listen(config.port, (err) => {
if (err) {
console.error(err);
}
});
};
2024-12-07 16:16:31 +00:00
2024-12-08 21:42:57 +00:00
start();