bahnui/back/dist/app.js
2024-11-16 01:19:31 +01:00

27 lines
1.1 KiB
JavaScript

import express from 'express';
import { createClient } from 'hafas-client';
import { profile as dbProfile } from 'hafas-client/p/db/index.js';
const app = express();
const port = 3000;
// Adapt this to your project! createClient() won't work with this string.
const userAgent = 'sperwing@sperwing.de';
// create a client with the Deutsche Bahn profile
const client = createClient(dbProfile, userAgent);
app.use((req, res, next) => {
res.append('Access-Control-Allow-Origin', ['*']);
res.append('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.append('Access-Control-Allow-Headers', 'Content-Type');
next();
});
app.get('/', (req, res) => {
client.journeys('8011167', '8000261', { results: 1 }).then(result => res.send(result));
});
app.get('/searchStation', (req, res) => {
let query = req.query;
console.log(query);
client.locations(query.text, { results: 1 }).then(result => res.send({ name: result[0].name, id: result[0].id }));
});
app.listen(port, () => {
return console.log(`Express is listening at http://localhost:${port}`);
});
//# sourceMappingURL=app.js.map