Denis
Denis

Reputation: 309

Angular 5 Universal: Using server.ts in Development

I used the new Angular Universal Starter to start a new Angular 5 project. For the new release they only give the Angular CLI version as a starter. Everything works fine and I can run my project in production with npm run serve:ssretc.

But: I have a custom API for the node.js/express server that acts as a wrapper for my backend.

When starting the project in development with ng serveor npm run startI have a working Angular application with automatic reload on file changes etc. Unfortunately in development the server.ts file is ignored, so my API wrapper is not available.

So did anyone get the new Angular Starter Kit up and running with the server.ts file used in development?

Upvotes: 2

Views: 2445

Answers (2)

Denis
Denis

Reputation: 309

On Github FriOne mentioned a better workaround using ts-node-dev:

ts-node-dev --fast --respawn server.dev.ts

To run this I duplicated the server.ts file to server.dev.ts only with the APIs I need to access while in dev. this way you can use ng serve for fast rebuilds while developing and still access your node-apis.

Upvotes: 4

wassertim
wassertim

Reputation: 3136

As of now angular cli does not support universal to run in dev mode. You can try nodemon if watching changes is what you need:

nodemon --ignore dist -e ts --exec 'npm run build:ssr && npm run serve:ssr'

It will restart every time you change a .ts file, but it will build the whole application again, so it is not fast.

Upvotes: 5

Related Questions