mvc 模板渲染
public | ||
src | ||
test | ||
views | ||
.eslintrc.js | ||
.gitignore | ||
.prettierrc | ||
nest-cli.json | ||
package.json | ||
pnpm-lock.yaml | ||
README.md | ||
tsconfig.build.json | ||
tsconfig.json |
模板引擎
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) < NestExpressApplication > AppModule;
app.useStaticAssets(join(__dirname, '..', 'public'));
app.setBaseViewsDir(join(__dirname, '..', 'views'));
app.setViewEngine('hbs');
await app.listen(3000);
}
bootstrap();
根目录创建这两个目录
public 公开的静态资源
views 存放模板文件
参考
文档 https://docs.nestjs.com/techniques/mvc#template-rendering