I already have an Angular application running in Azure Server using angular-cli to deploy.
All I have to do is run the command ng build --prod --aot
and copy everything from /dist
folder to my root website folder. Everything works great!
Because SEO issues, now I want to implement server side rendering. So I follow that universal rendering guide and I was able to create a server bundle.
Ok, so now I have 2 folders:
/dist
/dist-serv
And now? What I have to do to deploy it to Azure Server? Witch folder should I copy to my root folder so my webserver can start to pre render it?
2
Answers
This is how I deployed Angular to an production Azure server (IIS):
STEP ONE: Create an ANGULAR-CLI project. Instructions here: angular-cli
STEP TWO: Make it universal following this reference: universal-starter
Note: you can just clone this repository and bypass step 1
*How to fit one project into another:
Alright, now you have a default universal project. You should be able to run
npm run build:ssr && npm run serve:ssr
and/ornpm run build:prerender && npm run serve:prerender
Note: if you can't run above command you should double check all files in your project to be like the repository at step 2.STEP THREE:
Create a web.config file like this.
STEP FOUR: Copy and paste web.config to dist folder root like that:
STEP FIVE: Change server.ts file in your project like that:
STEP SIX Rebuild and copy everything from your
/dist
folder to your Azure website root.Enjoy =)
With server side rendering, copying the files to the root folder of your server is not enough.
You’ll need to run a web server (like Node.js Express) and call the renderModuleFactory up on an incoming request. See e.g. this post as an example, but there are many out there.