NestJS Angular Universal not loading “index.html” automatically on root path

谁都会走 提交于 2020-05-17 06:09:31

问题


I am running an NestJS Angular Universal app on my local server using Angular 9 and Ivy. I can get everything to work when I run:

npm run serve:ssr

However, nothing loads unless I type the route manually. I would think it would automatically load "index.html" without having to type it in.

localhost:8080 ----- nothing

localhost:8080/index.html ---- works

Is there a way to modify the code to do a rewrite for the root path? I would think this would not be necessary:

main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.setGlobalPrefix('api');
  await app.listen(process.env.PORT || 8080);
}

// Webpack will replace 'require' with '__webpack_require__'
// '__non_webpack_require__' is a proxy to Node 'require'
// The below code is to ensure that the server is run only when not requiring the bundle.
declare const __non_webpack_require__: NodeRequire;
const mainModule = __non_webpack_require__.main;
const moduleFilename = (mainModule && mainModule.filename) || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
  bootstrap().catch(err => console.error(err));
}

Or fix the problem at hand...


回答1:


After days of working on this, I figured out I had a loop by including a component that was including another component which had a loop in the ts file. In my case I was subscribing to something I shouldn't have. I thought this was an IVY / NestJS compatibility problem, but turns out it was my code.



来源:https://stackoverflow.com/questions/61242233/nestjs-angular-universal-not-loading-index-html-automatically-on-root-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!