#SSR not rendering / route

6 messages · Page 1 of 1 (latest)

idle chasm
#

Hello!

I have an Angular 14 Universal app which I am hosting on Firebase. Everything works as expected EXCEPT the / route...

When getting the / route, I receive the exact index.html file that I have, not rendered (blank page)...

This is my firebase.json:

  "functions": [
    {
      "source": "functions",
      "codebase": "default",
      "ignore": [...]
    }
  ],
  "hosting": {
    "public": "functions/browser",
    "ignore": [...],
    "rewrites": [
      {
        "source": "**",
        "function": "ngssr"
      }
    ]
  }
}```

This is my `ngssr` function:
```const functions = require("firebase-functions");
const mainFile = require(__dirname + "/server/main");

exports.ngssr = functions.https.onRequest(mainFile.app());```

This is my `server.ts`:
```...
export function app(): express.Express {
  const server = express();

  const websiteLocation = environment.production
    ? "browser"
    : "dist/functions/browser";
  const distFolder = join(process.cwd(), websiteLocation);
  const indexHtml = existsSync(join(distFolder, "index.original.html"))
    ? "index.original.html"
    : "index";

  server.engine(
    "html",
    ngExpressEngine({
      bootstrap: AppServerModule,
      inlineCriticalCss: false,
    })
  );

  server.set("view engine", "html");
  server.set("views", distFolder);

  server.get(
    "*.*",
    express.static(distFolder, {
      maxAge: "1y",
    })
  );

  server.get("*", (req, res) => {
    console.log("RENDERING", req.path);
    res.render(indexHtml, {
      req,
      providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }],
    });
  });

  return server;
}
...

Worth mentioning: I can see the console.log("RENDERING", <ROUTE>) for all routes except the / route.

Any help is very much appreciated. Thank you!

burnt cape
#

I believe Firebase, by default, serves index.html for the ' /' route. This behavior might be conflicting with your express routing setup for server-side rendering.

idle chasm
#

@burnt cape Is there any way I can change its default behaviour?

burnt cape
#

I don't think there is anyway to directly configure the default behavior. There might be a workaround for that

burnt cape
#

Can you try changing the nams of index.html to something else?

idle chasm
#

@burnt cape Your suggestion fixed the issue! Thank you! 🚀
I renamed index.html to main.html (plus some changes in servers.ts) and everything works fine now.