Skip to content

Commit b54672d

Browse files
wip
1 parent 3006e09 commit b54672d

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

features/lib/osrm_loader.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ class OSRMBaseLoader{
4848
var retryCount = 0;
4949
let retry = (err) => {
5050
if (err) {
51-
if (retryCount < 10) {
52-
// const timeoutMs = 10 * Math.pow(this.scope.OSRM_CONNECTION_EXP_BACKOFF_COEF, retryCount);
51+
if (retryCount < this.scope.OSRM_CONNECTION_RETRIES) {
52+
const timeoutMs = 10 * Math.pow(this.scope.OSRM_CONNECTION_EXP_BACKOFF_COEF, retryCount);
5353
retryCount++;
5454
setTimeout(() => {
5555
tryConnect(this.scope.OSRM_IP, this.scope.OSRM_PORT, retry);
56-
}, 1000);
56+
}, timeoutMs);
5757
} else {
5858
callback(new Error(`Could not connect to osrm-routed after ${this.scope.OSRM_CONNECTION_RETRIES} retries.`));
5959
}

features/support/env.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = function () {
4040

4141
this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000;
4242
this.OSRM_IP = process.env.OSRM_IP || '127.0.0.1';
43-
this.OSRM_CONNECTION_RETRIES = process.env.OSRM_CONNECTION_RETRIES && parseInt(process.env.OSRM_CONNECTION_RETRIES) || 10;
43+
this.OSRM_CONNECTION_RETRIES = process.env.OSRM_CONNECTION_RETRIES && parseInt(process.env.OSRM_CONNECTION_RETRIES) || 100;
4444
this.OSRM_CONNECTION_EXP_BACKOFF_COEF = process.env.OSRM_CONNECTION_EXP_BACKOFF_COEF && parseFloat(process.env.OSRM_CONNECTION_EXP_BACKOFF_COEF) || 1.0;
4545

4646
this.HOST = `http://${this.OSRM_IP}:${this.OSRM_PORT}`;

server/server.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function main() {
157157
rewriteUrl: (req) => {
158158
// https://github.com/fastify/fastify/issues/2487
159159
// TODO: why url is optional?
160-
const u = req.url.replace(';', '-');
160+
const u = req.url.replace(';', '%3B');
161161
console.log(u);
162162
return u;
163163
}
@@ -167,18 +167,26 @@ function main() {
167167
}));
168168
// TODO: validation
169169
fastify.get('/:service(route|nearest|table|match|trip|tile)/v1/:profile/:coordinates', (request, reply) => __awaiter(this, void 0, void 0, function* () {
170-
var _a;
171170
const { service, profile, coordinates } = request.params;
172171
const query = request.query;
173-
const parsedCoordinates = coordinates.split('-').map((c) => c.split(',').map((n) => parseFloat(n)));
172+
const parsedCoordinates = coordinates.split(';').map((c) => c.split(',').map((n) => parseFloat(n)));
174173
const handlers = new Map();
175174
handlers.set('nearest', handleNearest);
176175
handlers.set('route', handleRoute);
177176
handlers.set('table', handleTable);
178177
handlers.set('trip', handleTrip);
179178
handlers.set('match', handleMatch);
180179
reply.type('application/json').code(200);
181-
return (_a = handlers.get(service)) === null || _a === void 0 ? void 0 : _a(osrm, parsedCoordinates, query);
180+
const handler = handlers.get(service);
181+
if (handler == null) {
182+
return {
183+
code: 'InvalidService',
184+
message: `Service ${service} not found!`
185+
};
186+
}
187+
const result = yield handler(osrm, parsedCoordinates, query);
188+
result['code'] = 'Ok';
189+
return result;
182190
}));
183191
fastify.listen({ port: argv.port, host: argv.ip }, (err, address) => {
184192
if (err) {

server/server.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async function main() {
134134
rewriteUrl: (req) => {
135135
// https://github.com/fastify/fastify/issues/2487
136136
// TODO: why url is optional?
137-
const u = req.url!.replace(';', '-');
137+
const u = req.url!.replace(';', '%3B');
138138
console.log(u);
139139
return u
140140
}
@@ -148,7 +148,7 @@ async function main() {
148148
fastify.get('/:service(route|nearest|table|match|trip|tile)/v1/:profile/:coordinates', async (request, reply) => {
149149
const { service, profile, coordinates } = request.params as any;
150150
const query = request.query as any;
151-
const parsedCoordinates = coordinates.split('-').map((c: string) => c.split(',').map((n: string) => parseFloat(n)));
151+
const parsedCoordinates = coordinates.split(';').map((c: string) => c.split(',').map((n: string) => parseFloat(n)));
152152

153153
const handlers: Map<string, Function> = new Map();
154154
handlers.set('nearest', handleNearest);
@@ -159,8 +159,18 @@ async function main() {
159159

160160
reply.type('application/json').code(200)
161161

162+
const handler = handlers.get(service);
162163

163-
return handlers.get(service)?.(osrm, parsedCoordinates, query);
164+
if (handler == null) {
165+
return {
166+
code: 'InvalidService',
167+
message: `Service ${service} not found!`
168+
}
169+
}
170+
171+
const result = await handler(osrm, parsedCoordinates, query);
172+
result['code'] = 'Ok';
173+
return result;
164174
})
165175

166176
fastify.listen({ port: argv.port, host: argv.ip }, (err, address) => {

0 commit comments

Comments
 (0)