【发布时间】:2019-07-17 04:58:54
【问题描述】:
我正在制作 Angular + NestJS 应用程序,我想为所有路由发送 index.html 文件。
main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useStaticAssets(join(__dirname, '..', 'frontend', 'dist', 'my-app'));
app.setBaseViewsDir(join(__dirname, '..', 'frontend', 'dist', 'my-app'));
await app.listen(port);
}
app.controller.ts
@Controller('*')
export class AppController {
@Get()
@Render('index.html')
root() {
return {};
}
}
当我打开 localhost:3000/ 时,它运行良好,但如果我打开 localhost:3000/some_route,服务器会显示 500 internal error 并显示 Can not find html module。
我正在寻找为什么我会收到这个错误,每个人都说set default view engine like ejs or pug,但我不想使用一些引擎,我只想发送由 angular 构建的普通 html,而不像res.sendFile('path_to_file') 那样进行黑客攻击。请帮忙
【问题讨论】:
标签: javascript node.js typescript express nestjs