Skip to content

Commit

Permalink
feat(core): Expose additional bootstrap options (#2568)
Browse files Browse the repository at this point in the history
This allows eg support for NestJS devtools
  • Loading branch information
alexisvigoureux authored Dec 14, 2023
1 parent 1098a47 commit 3b6d6ab
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@nestjs/apollo": "^12.0.7",
"@nestjs/common": "10.2.1",
"@nestjs/core": "10.2.1",
"@nestjs/devtools-integration": "0.1.5",
"@nestjs/graphql": "12.0.8",
"@nestjs/platform-express": "10.2.1",
"@nestjs/terminus": "10.0.1",
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { I18nService } from './i18n/i18n.service';
import { PluginModule } from './plugin/plugin.module';
import { ProcessContextModule } from './process-context/process-context.module';
import { ServiceModule } from './service/service.module';
import { DevtoolsModule } from "@nestjs/devtools-integration";

@Module({
imports: [
Expand All @@ -23,6 +24,10 @@ import { ServiceModule } from './service/service.module';
HealthCheckModule,
ServiceModule,
ConnectionModule,
DevtoolsModule.register({
port: process.env.DEVTOOLS_PORT ? +process.env.DEVTOOLS_PORT : 8000,
http: process.env.NODE_ENV !== 'production' && process.env.ENABLE_DEVTOOLS === 'true',
}),
],
})
export class AppModule implements NestModule, OnApplicationShutdown {
Expand Down
16 changes: 14 additions & 2 deletions packages/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,19 @@ import { getPluginStartupMessages } from './plugin/plugin-utils';
import { setProcessContext } from './process-context/process-context';
import { VENDURE_VERSION } from './version';
import { VendureWorker } from './worker/vendure-worker';
import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';

export type VendureBootstrapFunction = (config: VendureConfig) => Promise<INestApplication>;

export interface BootstrapOptions {
nestApplicationOptions: NestApplicationOptions;
}

export interface BootstrapWorkerOptions {
nestApplicationContextOptions: NestApplicationContextOptions
}

/**
* @description
* Bootstraps the Vendure server. This is the entry point to the application.
Expand All @@ -42,7 +52,7 @@ export type VendureBootstrapFunction = (config: VendureConfig) => Promise<INestA
* ```
* @docsCategory common
* */
export async function bootstrap(userConfig: Partial<VendureConfig>): Promise<INestApplication> {
export async function bootstrap(userConfig: Partial<VendureConfig>, options?: BootstrapOptions): Promise<INestApplication> {
const config = await preBootstrapConfig(userConfig);
Logger.useLogger(config.logger);
Logger.info(`Bootstrapping Vendure Server (pid: ${process.pid})...`);
Expand All @@ -58,6 +68,7 @@ export async function bootstrap(userConfig: Partial<VendureConfig>): Promise<INe
const app = await NestFactory.create(appModule.AppModule, {
cors,
logger: new Logger(),
...options?.nestApplicationOptions
});
DefaultLogger.restoreOriginalLogLevel();
app.useLogger(new Logger());
Expand Down Expand Up @@ -99,7 +110,7 @@ export async function bootstrap(userConfig: Partial<VendureConfig>): Promise<INe
* ```
* @docsCategory worker
* */
export async function bootstrapWorker(userConfig: Partial<VendureConfig>): Promise<VendureWorker> {
export async function bootstrapWorker(userConfig: Partial<VendureConfig>, options?: BootstrapWorkerOptions): Promise<VendureWorker> {
const vendureConfig = await preBootstrapConfig(userConfig);
const config = disableSynchronize(vendureConfig);
config.logger.setDefaultContext?.('Vendure Worker');
Expand All @@ -113,6 +124,7 @@ export async function bootstrapWorker(userConfig: Partial<VendureConfig>): Promi
const WorkerModule = await import('./worker/worker.module.js').then(m => m.WorkerModule);
const workerApp = await NestFactory.createApplicationContext(WorkerModule, {
logger: new Logger(),
...options?.nestApplicationContextOptions
});
DefaultLogger.restoreOriginalLogLevel();
workerApp.useLogger(new Logger());
Expand Down
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3708,6 +3708,14 @@
path-to-regexp "3.2.0"
tslib "2.6.1"

"@nestjs/devtools-integration@0.1.5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@nestjs/devtools-integration/-/devtools-integration-0.1.5.tgz#373aebe93632dd0f1bc46b714c6720951f35f87b"
integrity sha512-iwxvfxa3kzOulG/Fje82Ww80OVsA8rzYR+UAEKrdGExRRGQRGQ0+bHfG0XLlPG3XIuM5J2MRMo7x1bN8ZIs9Gg==
dependencies:
chalk "^4.1.2"
node-fetch "^2.6.9"

"@nestjs/graphql@12.0.8":
version "12.0.8"
resolved "https://registry.yarnpkg.com/@nestjs/graphql/-/graphql-12.0.8.tgz#15143b76dfb5fa4dc880d68a1bf2f7159ea077b6"
Expand Down Expand Up @@ -14102,7 +14110,7 @@ node-fetch@2.6.7:
dependencies:
whatwg-url "^5.0.0"

node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.12, node-fetch@^2.6.7, node-fetch@^2.7.0:
node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.12, node-fetch@^2.6.7, node-fetch@^2.6.9, node-fetch@^2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
Expand Down

0 comments on commit 3b6d6ab

Please sign in to comment.