【发布时间】:2021-03-07 00:03:43
【问题描述】:
我想根据这个文档https://docs.nestjs.com/recipes/serve-static#serve-static 提供一些静态目录结构,但可以找到这些简单问题的答案:
- 如何设置像'/some/path/to/files'这样的路径前缀?
- 如何设置运行时服务(文件路径是动态的,不能硬编码)?
提前致谢。
附:我看到了一些关于 app.useStaticAssets() 的答案,但据我所知,这是 Express 特定的解决方案,无论如何都不会用最新版本编译 (Property 'useStaticAssets' does not exist on type 'INestApplication')...
更新
例如,我有这些目录:
- /var/lib/app/data1
- /var/lib/app/data2
- /home/user/some/path
我希望它被用作:
【问题讨论】:
-
wont compile with latest version anyway我建议你在一个新线程上问这个问题。如您所见,他们的官方文档中记录了对静态内容的支持。他们甚至包括完整的解决方案,可以毫无问题地构建和运行:github.com/nestjs/nest/tree/master/sample/24-serve-static -
根据官方文档,您有两个选择:
Under the hood, Nest makes use of robust HTTP Server frameworks like Express (the default) and optionally can be configured to use Fastify as well!docs.nestjs.com 提供静态内容应该适用于任一选项。
标签: nestjs