Skip to content

Commit

Permalink
Merge pull request #326 from gas-buddy/fix/routes-for-js-entrypoint
Browse files Browse the repository at this point in the history
Properly load routes for apps using javascript file as entrypoint
  • Loading branch information
dhruv-m-patel committed Dec 15, 2023
2 parents 52b2388 + e23efa8 commit 7a8791a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gasbuddy/service",
"version": "12.20.0",
"version": "12.20.1",
"description": "An opinionated framework for building configuration driven services - web, api, or job. Uses swagger, pino logging, express, confit, Typescript and Jest.",
"main": "build/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export async function bootstrap<
rootDirectory,
service: impl.default || impl.service,
codepath,
useJsEntrypoint,
};
const { startApp, listen } = await import('./express-app/app.js');
const app = await startApp<SLocals, RLocals>(opts);
Expand Down
5 changes: 3 additions & 2 deletions src/express-app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export async function startApp<
RLocals extends RequestLocals = RequestLocals,
>(startOptions: ServiceStartOptions<SLocals, RLocals>): Promise<ServiceExpress<SLocals>> {
const {
service, rootDirectory, codepath = 'build', name,
service, rootDirectory, codepath = 'build', name, useJsEntrypoint,
} = startOptions;
const shouldPrettyPrint = isDev() && !process.env.NO_PRETTY_LOGS;
const destination = pino.destination({
Expand Down Expand Up @@ -258,10 +258,11 @@ export async function startApp<
}

if (routing?.routes) {
const routeFileExtension = useJsEntrypoint ? 'js' : 'ts';
await loadRoutes(
app,
path.resolve(rootDirectory, codepath, config.get('routing:routes')),
codepath === 'build' ? '**/*.js' : '**/*.ts',
codepath === 'build' ? '**/*.js' : `**/*.${routeFileExtension}`,
);
}
if (routing?.openapi) {
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export interface ServiceStartOptions<
// locals: { stuff } as Partial<MyLocals>
locals?: Partial<SLocals>;

useJsEntrypoint?: boolean;

// And finally, the function that creates the service instance
service: () => Service<SLocals, RLocals>;
}
Expand Down

0 comments on commit 7a8791a

Please sign in to comment.