johnpapa / angular-tour-of-heroes

Angular - Tour of Heroes - The Next Step after Getting Started
Apache License 2.0
826 stars 1.45k forks source link

Make the backend-uri configurable #148

Open JocaPC opened 5 years ago

JocaPC commented 5 years ago

I'm working on Microsoft SQL Server and I want to create Angular demo app that shows how to implement it end-to-end solution using real backend (.Net) and database (SQL Server). Current version is here: https://github.com/JocaPC/sql-server-samples/tree/angular-tour-of-heroes/src/

I have used this code as front-end, I have created back-end/database, and everything is working fine.

However, the problem is that I had to do few source code changes to make it work, and it would be nicer if these are some config values that can be changed instead of chaining the code. The changes that I made are:

  1. Add the backendUri in environment config: https://github.com/JocaPC/sql-server-samples/blob/angular-tour-of-heroes/src/frontend/src/environments/environment.ts#L8
  2. Change the backend URL in the code: https://github.com/JocaPC/sql-server-samples/blob/angular-tour-of-heroes/src/frontend/src/app/hero.service.ts#L11
  3. Change the backend URL in search service https://github.com/JocaPC/sql-server-samples/blob/angular-tour-of-heroes/src/frontend/src/app/hero-search.service.ts#L15
  4. Disable in-memory data source here: https://github.com/JocaPC/sql-server-samples/blob/angular-tour-of-heroes/src/frontend/src/app/app.module.ts#L24

It works for me but it would be good if the backend URL is placed in the config in your code too because I believe that other people will like to do the same. Also, it would be good do if we could disable InMemoryDataService without changing the code. Ideally this could be some property that could be changed if I deploy the app in Azure Web Apps.

If you know have some better way to re-configure this sample to work with some backend, could you point me to some instruction in docs? Otherwise what do you think about adding this in your code? I can send the PR for backendUri if you agree, but I'm not sure what would be the best way to disable InMemoryDataSource.