bound 默认设置根目录下的 public 文件夹为静态文件存放位置。

    1. // main.ts
    2. import { NestFactory } from '@nestjs/core'
    3. import { Logger } from '@nestjs/common'
    4. import { NestExpressApplication } from '@nestjs/platform-express'
    5. import { AppModule } from './app.module'
    6. import config from './config'
    7. async function bootstrap() {
    8. const app = await NestFactory.create<NestExpressApplication>(AppModule)
    9. ...
    10. ...
    11. app.useStaticAssets(`${config.APP}/public`); // 设置静态文件位置
    12. await app.listen(config.PORT)
    13. Logger.log(`app is listening to ${config.PORT}`)
    14. }
    15. bootstrap();

    以下面的文件结构为例
    image.png
    访问 http://localhost:8080/logo.png 可以看到如下效果:
    image.png
    更多静态服务相关的内容,可以参考 静态服务