Skip to content

Commit

Permalink
fix(asset-server-plugin): Do not run server logic in worker context
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Jul 29, 2021
1 parent 7c30f0e commit c3a67b6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/asset-server-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AssetStorageStrategy,
Logger,
PluginCommonModule,
ProcessContext,
registerPluginStartupMessage,
RuntimeVendureConfig,
VendurePlugin,
Expand Down Expand Up @@ -159,8 +160,13 @@ export class AssetServerPlugin implements NestModule, OnApplicationBootstrap {
return config;
}

constructor(private processContext: ProcessContext) {}

/** @internal */
onApplicationBootstrap(): void | Promise<void> {
if (this.processContext.isWorker) {
return;
}
if (AssetServerPlugin.options.presets) {
for (const preset of AssetServerPlugin.options.presets) {
const existingIndex = this.presets.findIndex(p => p.name === preset.name);
Expand All @@ -177,6 +183,9 @@ export class AssetServerPlugin implements NestModule, OnApplicationBootstrap {
}

configure(consumer: MiddlewareConsumer) {
if (this.processContext.isWorker) {
return;
}
Logger.info('Creating asset server middleware', loggerCtx);
consumer.apply(this.createAssetServer()).forRoutes(AssetServerPlugin.options.route);
registerPluginStartupMessage('Asset server', AssetServerPlugin.options.route);
Expand Down

0 comments on commit c3a67b6

Please sign in to comment.