Angular server side rendering. What did i learn?

I have finished an angular application full support server side rendering. I write some notes for this. Detail will be explained in next article.

You can check sample app here.

  1. Make an angular app can render from server side is not easy. You must care to many things. Ex: which library can use in server side? Call API twice..

Tip: use webpack to replace unsupported module. Below is my sample code for replace quill editor.

new webpack.NormalModuleReplacementPlugin(
/quill/,
path.join(__dirname, 'src/app/shared/servermocks/quillmodule.mock.ts')
)

2. All code inside lifecycle of component will run two times. Ex: generate UI, call service …

Tip: Use ServerTransferStateModule for re-use state from server. You can refer this for good advice.

3. Should use resolve to fetching data before render router.

4. Deploy

Need a node.js server for server side. Can use heroku, AWS lambda, google cloud function…

5. Be careful when use ES8 features on node.js. Check this more detail

6. isPlatformBrowser() , isPlatformServer() are useful functions.