一、配置静态资源目录
- src/main.ts ```typescript import { NestFactory } from ‘@nestjs/core’; import { AppModule } from ‘./app.module’; import { NestExpressApplication } from ‘@nestjs/platform-express’; // 引入配置静态资源目录 import { join } from ‘path’; // 将数组元素转换为字符串
async function bootstrap() {
const app = await NestFactory.create
<a name="FMw9S"></a>### 二、配置虚拟目录- 我们也可以配置虚拟目录,比如我们想通过 [http://localhost:3000/static/1.jpg](http://localhost:3000/static/1.jpg) 来访问 public 目录里面的文件,这时候代码如下:```typescriptapp.useStaticAssets(join(__dirname, '..', 'public'), {prefix: '/static',});
三、配置模板引擎
- npm install —save hbs
- https://docs.nestjs.cn/8/techniques?id=mvc%e6%a8%a1%e5%9e%8b-%e8%a7%86%e5%9b%be%e6%8e%a7%e5%88%b6%e5%99%a8
- src/main.ts
app.setBaseViewsDir(join(__dirname, '..', 'views')); // 配置模板引擎目录app.setViewEngine('hbs'); // 使用模板引擎
