网站搜索

javascript - NestJS 单体仓库微服务 EJS 错误 无法在视图目录 "..\fin\dist\.." 中查找视图 "index"


我正在使用 fin 作为默认微服务,在单仓库中构建一个 NestJS 微服务应用。

我正在使用 EJS 模板。

但是一旦我运行项目,我就会收到错误:“ERROR [ExceptionsHandler] 在视图目录 'D:\Studio\Work...\fin\dist\apps\views' 中查找视图 'index' 失败。”

我尝试了在 app.setBaseViewsDir() 中设置目录路径的不同配置,但都没有成功;

你能帮我找出问题吗?

提前谢谢!

项目目录文件夹看起来如下;

+ fin
  + apps 
    + fin
      + src
        + views 

          -index.ejs

        -app.controller.ts

        -main.ts
  + image      

  -package.json

  -tsconfig.json

最终的 main.ts 文件看起来如下;

main.ts:

import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { resolve } from 'path';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  app.useStaticAssets(resolve('../src/assets'));
  app.setBaseViewsDir(resolve('../src/views'));
  app.setViewEngine('ejs');
  await app.listen(6006);
  console.log(`Fin PEN started successfully on Port 6006`);
}
bootstrap();

tsconfig.json 看起来如下。

tsconfig.json:

{
  "compilerOptions": {
    ...
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./"
    ...
  }
}