Skip to content

Commit

Permalink
Merge pull request #1260 from input-output-hk/chore/LW-7619-windows-n…
Browse files Browse the repository at this point in the history
…o-backslash

chore: register HTTP handlers with forward slashes on Windows
  • Loading branch information
iccicci committed May 9, 2024
2 parents 7b3254d + 572ae9f commit ebaa2ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/cardano-services/src/Http/HttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ export class HttpServer extends RunnableModule {
};

let handler: keyof typeof handlers;
for (handler in handlers) this.app.use(path.join(versionPath, handler), handlers[handler]);
// Note: `.replaceAll(path.sep, '/')` is needed on Windows:
for (handler in handlers)
this.app.use(path.join(versionPath, handler).replaceAll(path.sep, '/'), handlers[handler]);
}

static sendJSON<ResponseBody>(
Expand Down Expand Up @@ -268,7 +270,10 @@ export class HttpServer extends RunnableModule {
includePath: true,
promRegistry,
...this.#config.metrics?.options,
metricsPath: path.join(versionPath, this.#config.metrics?.options?.metricsPath || '/metrics')
// Note: `.replaceAll(path.sep, '/')` is needed on Windows:
metricsPath: path
.join(versionPath, this.#config.metrics?.options?.metricsPath || '/metrics')
.replaceAll(path.sep, '/')
})
);
this.logger.info(
Expand Down
6 changes: 4 additions & 2 deletions packages/cardano-services/test/Http/HttpServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,15 @@ describe('HttpServer', () => {
{
body: { bigint: 23n, check: 'ok', test: 42 },
method: 'POST',
path: path.join(someServiceVersionPath, 'stake-pool', 'echo'),
// Note: `.replaceAll(path.sep, '/')` is needed on Windows:
path: path.join(someServiceVersionPath, 'stake-pool', 'echo').replaceAll(path.sep, '/'),
query: {}
},
{
body: {},
method: 'GET',
path: path.join(someServiceVersionPath, 'stake-pool', 'echo'),
// Note: `.replaceAll(path.sep, '/')` is needed on Windows:
path: path.join(someServiceVersionPath, 'stake-pool', 'echo').replaceAll(path.sep, '/'),
query: { bigint: '23', check: 'ok', test: '42' }
}
]);
Expand Down

0 comments on commit ebaa2ad

Please sign in to comment.