1

场景

在官方提供的文档中提供方式,
file

app.module.ts

 ServeStaticModule.forRoot({
      rootPath: path.join(process.cwd(), 'static'),
      serveStaticOptions: {
        maxAge: 10000,
      },
    }),

其中提供了一个静态资源目录,如果想使用多个静态目录,可以在app配置中间件

import * as express from 'express';
import * as path from 'path';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { cors: true });
  //静态资源目录
  app.use(express.static(path.join(process.cwd(), './public')));
  
  const options = new DocumentBuilder()
    .setTitle('Nike Snkrs Open API')
    .setDescription('Nike snkrs 一些api')
    .setVersion('1.0')
    .build();

  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);
  await app.listen(9011);
}
博客: https://github.com/zhaojunlike

Godtoy
2.4k 声望114 粉丝

Technology change the 'hello world'