Reputation: 168
I have a public-facing angular frontend which hits a .NetCore back end. The two projects are bundled together using webpack. The problem is, I need Server Side Rendering enabled and Microsoft has deprecated /made UseSpaPrerendering obsolete. I did follow this tutorial but it doesn't work well in .net core 3.0/3.1 very well at all. When I get this working, I get a FOUC (Flash of unrendered content) and the page load speed is very slow.
With the above being the case, how can I deploy a .net core API/Angular front end application with server-side rendering?
Upvotes: 4
Views: 948
Reputation: 3591
Did you already try to deploy the application to IIS? Or you could also change your ASPNETCORE_ENVIRONMENT (Project properties --> Debug --> ASPNETCORE_ENVIRONMENT = Production) to prod, and just run the application.
Now the angular bundles aren't built when running the app. To do so, you have to run the following commands from the ClientApp folder (check your csproj file, they're right there):
npm run build --prod
npm run build:ssr --prod
Now the angular build files are generated. If you see a dist/browser folder next to the dist/server folder, then the app won't render in Production mode. The contents of the browser folder should be next to the server folder (this is a known bug, but Microsoft will no longer change this). If this is not the case, you can always get around this by changing your angular.json file: projects:ClientApp:architect:build:options:outputPath = dist and not dist/browser. This way the app will behave the same in Development mode as Production mode. The "browser" files will always end up in the dist-folder, and ASP.NET Core will always look in the dist-folder, regardless the environment settings.
After your angular server/browser files have been built, you should be able to run the application in prod mode as regular.
Can you try this? I will try as well.
Update:
I tried my guide from https://medium.com/@pieterjandeclippel/server-side-rendering-in-asp-net-core-angular-6df7adacbdaa, with .NET Core 3.1 and it still seems to be working.
Could you try to perform following steps?:
Run the following commands from your ClientApp folder: npm run build --prod
and npm run build:ssr --prod
Open your project properties page → Debug tab → Change ASPNETCORE_ENVIRONMENT to Production
What result do you get? You can also read a lot of information from the Output window if something like this isn't working well...
If this is working, then it appears you just have to be more patient, and wait for the server build files to appear. So during development:
Upvotes: 4