我想在 NestJS
中使用 pug
布局,但是当从绝对路径扩展布局时,pug
要求设置 basedir
选项。
在 ExpressJS 中,您会使用 app.locals.basedir = ...
,那么在 NestJS 中等价的是什么?
const server = await NestFactory.create<NestExpressApplication>(AppModule);
server.setViewEngine('pug');
server.setBaseViewsDir(join(__dirname, 'templates', 'views'));
await server.listen(config.server.port);
在视图中使用
extends /layouts/index
会引发以下错误:the "basedir" option is required to use includes and extends with "absolute" paths
。我不想使用相对路径,因为这很快就变得非常麻烦。例如:
extends ../../../layouts/index
。
getHttpAdapter().getInstance()
访问它,然后就能设置locals.basedir
。 - woutr_begetHttpAdatper().getInstance()
。我认为总体来说这是更好的方法,但知道两种方法都可以也很好。 - Jay McDoniel