skip to Main Content

I’m trying to set up angular universal on angular7 with asp.net core 2.1. The prerendering works perfectly on a local build but does not add code to the page source on a server in production with no errors or logs.

Due to the lack of logs I suspect this is because the server module is not loaded/ started but I have no idea why. Is this something that should be added into the web config?

I am using a windows shared plesk server which supports node.js and IIS Node. Here is a snippet from my Startup.cs

app.UseSpa(spa =>
{
    spa.Options.StartupTimeout = new System.TimeSpan(0, 0, 1000);
    spa.Options.SourcePath = "ClientApp";

    spa.UseSpaPrerendering(options =>
    {
        options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.js";
        options.BootModuleBuilder = env.IsDevelopment() ? new 
        AngularCliBuilder(npmScript: "build:ssr") : null;
        options.ExcludeUrls = new[] { "/sockjs-node" };
    });

    if (env.IsDevelopment())
    {
        spa.UseAngularCliServer(npmScript: "start");
    }
});

2

Answers


  1. Chosen as BEST ANSWER

    I eventually realised I had the line app.UseStaticFiles(); as well as app.UseSpaStaticFiles in Startup.cs. Removing app.UseStaticFiles(); solved this issue. However, I am still not sure why this wasn't causing issues on a local build.


  2. I believe you are misusing the prerendering middleware.

    About prerendering: Represents the ability to build a Single Page Application (SPA) on demand so that it can be prerendered. This is only intended to be used at development time. In production, a SPA should already have been built during publishing.

    You should hide that piece of code behind:

    env.IsDevelopment()
    

    Read more here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search