更改 nestjs 的徽标和 header 颜色以及 swagger-ui

Change the logo and header colour of nestjs and swagger-ui

我已经安装了 nestjs,我想使用 swagger-ui。我不确定更改徽标和 header 的最佳方法是什么。

在main.ts

  const options = new DocumentBuilder()
    .setTitle('Data Service API')
    .setDescription('Data Service API')
    .setVersion('1.0')
    .addTag('OD')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);

我想通了。

  const options2 = {
  // customCss: '.swagger-ui .topbar { display: none }'
    customCss: `
    .topbar-wrapper img {content:url(\'../assets/img/lbglogo.png\'); width:300px; height:auto;}
    .swagger-ui .topbar { background-color: white; }

    `
};

  SwaggerModule.setup('api', app, document, options2);

  app.useStaticAssets(join(__dirname,'..', 'public'), {prefix: '/assets'});

参考: https://www.npmjs.com/package/swagger-ui-express