53 lines
1.4 KiB
JavaScript
Executable File
53 lines
1.4 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
import express from 'express';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import {createClient} from 'db-vendo-client/index.js';
|
|
import {profile as dbnavProfile} from 'db-vendo-client/p/dbnav/index.js';
|
|
import {mapRouteParsers} from 'db-vendo-client/lib/api-parsers.js';
|
|
import {createHafasRestApi as createApi} from 'hafas-rest-api';
|
|
|
|
const webdir_from_module = path.join(path.dirname(fileURLToPath(import.meta.url)), 'web');
|
|
|
|
const config = {
|
|
hostname: process.env.HOSTNAME || 'localhost',
|
|
port: process.env.HTTP_PORT ? parseInt(process.env.HTTP_PORT) : 3000,
|
|
address: process.env.HTTP_ADDRESS || '::1',
|
|
webdir: process.env.WEBDIR || webdir_from_module,
|
|
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 app = express();
|
|
|
|
const vendo = createClient(
|
|
dbnavProfile,
|
|
'traveldrafter',
|
|
config,
|
|
);
|
|
const api = await createApi(vendo, config);
|
|
|
|
app.use("/api", api);
|
|
app.use('/', express.static(config.webdir));
|
|
|
|
app.listen(config.port, config.address, (err) => {
|
|
if (err) {
|
|
console.error(err);
|
|
}
|
|
});
|
|
};
|
|
|
|
start();
|