Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP make /route-rt use CH for bike-only route #27

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FROM node:20.12-alpine
WORKDIR /app
RUN apk --no-cache add dumb-init
RUN apk --no-cache add curl dumb-init
COPY package.json /app
COPY package-lock.json /app
RUN npm install
COPY ./src /app/src
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ./node_modules/.bin/nodemon --inspect=0.0.0.0:9229 src/index.js
CMD node --inspect=0.0.0.0:9229 /app/src/index.js
9 changes: 6 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
services:
static:
container_name: static-content
container_name: static
image: nginx
ports:
- 8765:80
volumes:
- ./volumes/static:/usr/share/nginx/html

bikehopper-web-app:
container_name: bikehopper-web-app
restart: unless-stopped
Expand All @@ -17,7 +18,6 @@ services:
PORT: "${WEB_APP_CONTAINER_PORT}"
HOSTNAME: svc.cluster.local
PHOTON_SERVICE_NAME: photon:2322
GRAPHHOPPER_SERVICE_NAME: graphhopper:8989
NODE_ENV: development
NOMINATIM_SERVICE_NAME: nominatim
NAMESPACE: "${NAMESPACE}"
Expand Down Expand Up @@ -48,7 +48,10 @@ services:
ports:
- 9229:9229
- ${WEB_APP_CONTAINER_PORT}:${WEB_APP_CONTAINER_PORT}

depends_on:
- cache
- static

cache:
container_name: cache
image: eqalpha/keydb
Expand Down
2 changes: 0 additions & 2 deletions src/graphhopper/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import axios from 'axios';
import {
PROTOCOL,
GRAPHHOPPER_SERVICE_NAME,
HOSTNAME,
NAMESPACE
} from '../config.js';

const client = axios.create({
Expand Down
21 changes: 18 additions & 3 deletions src/graphhopper/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,28 @@ router.get('/route-pt', async (req, res) => {
method: 'get',
url: req.url,
});
const bikeRoutePromise = graphHopperClient.post('/route', {
profile: 'bike2',
locale: 'en-US',
elevation: true,
useMiles: false,
layer: 'OpenStreetMap',
pointsEncoded: false,
details: ['cycleway', 'road_class', 'street_name'],
points: req.query.point.map(latlng => latlng.split(',').reverse().map(point => parseFloat(point))) // turning [['1.2,3.4'],['5.6,7.8']] -> [[3.4, 1.2], [7.8, 5.6]]
});

const [alertResult, graphHopperResult] = await Promise.allSettled([
alertPromise, graphHopperPromise
const [alertResult, graphHopperResult, bikeRouteResult] = await Promise.allSettled([
alertPromise, graphHopperPromise, bikeRoutePromise
]);

if (graphHopperResult.status === 'rejected') throw graphHopperResult.reason;
if (alertResult.status === 'rejected') logger.error(alertResult.reason);
if (bikeRouteResult.status === 'rejected') logger.error(bikeRouteResult.reason.message);

if (bikeRouteResult.status !== 'rejected' && bikeRouteResult.value?.data?.paths) {
graphHopperResult.value.data.paths.push(...bikeRouteResult.value.data.paths);
}

res.json(mergeAlertsIntoRoutes(alertResult.value, graphHopperResult.value.data));
} catch (error) {
Expand Down Expand Up @@ -66,7 +81,7 @@ passthruRoutes.forEach(([method, path]) => {
router[method](path, async (req, res) => {
try {
const resp = await graphHopperClient.request({
method: req.method.toLowerCase(),
method: method,
url: req.url
});
res.send(resp.data);
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { router as geoConfigRouter } from './geoconfig/index.js';
import { router as realtimeRouter } from './realtime-gtfs/index.js';

if (!satisfies(process.version, '>=18')) {
console.error('ERROR: bikehopper-web-app requires node v18');
console.error('ERROR: bikehopper-web-app requires node v18+');
process.exit(1);
}

Expand Down
Loading