Browse Source

feat(server): Add 'silent' option to VendureConfig

Michael Bromley 7 years ago
parent
commit
537e26b988

+ 4 - 1
server/src/bootstrap.ts

@@ -22,7 +22,10 @@ export async function bootstrap(userConfig: Partial<VendureConfig>): Promise<INe
     // config, so that they are available when the AppModule decorator is evaluated.
     // tslint:disable-next-line:whitespace
     const appModule = await import('./app.module');
-    const app = await NestFactory.create(appModule.AppModule, { cors: config.cors });
+    const app = await NestFactory.create(appModule.AppModule, {
+        cors: config.cors,
+        logger: config.silent ? false : undefined,
+    });
     await app.listen(config.port);
     return app;
 }

+ 1 - 0
server/src/config/default-config.ts

@@ -29,6 +29,7 @@ export const defaultConfig: ReadOnlyRequired<VendureConfig> = {
         origin: true,
         credentials: true,
     },
+    silent: false,
     authOptions: {
         disableAuth: false,
         tokenMethod: 'cookie',

+ 4 - 0
server/src/config/vendure-config.ts

@@ -214,6 +214,10 @@ export interface VendureConfig {
      * Which port the Vendure server should listen on.
      */
     port: number;
+    /**
+     * When set to true, no application logging will be output to the console.
+     */
+    silent?: boolean;
     /**
      * Configuration for authorization.
      */

+ 3 - 2
server/src/plugin/default-asset-server/default-asset-server-plugin.ts

@@ -50,7 +50,7 @@ export class DefaultAssetServerPlugin implements VendurePlugin {
         });
         config.assetOptions.assetStorageStrategy = this.assetStorage;
         config.middleware.push({
-            handler: this.createProxyHandler(),
+            handler: this.createProxyHandler(!config.silent),
             route: this.options.route,
         });
         return config;
@@ -115,13 +115,14 @@ export class DefaultAssetServerPlugin implements VendurePlugin {
      * Configures the proxy middleware which will be passed to the main Vendure server. This
      * will proxy all asset requests to the dedicated asset server.
      */
-    private createProxyHandler() {
+    private createProxyHandler(logging: boolean) {
         const route = this.options.route.charAt(0) === '/' ? this.options.route : '/' + this.options.route;
         return proxy({
             target: `${this.options.hostname}:${this.options.port}`,
             pathRewrite: {
                 [`^${route}`]: '/',
             },
+            logLevel: logging ? 'info' : 'silent',
         });
     }