auth0-blog / angular2-authentication-sample

This is a sample that shows how to add authentication to an Angular 2 (ng2) app
MIT License
966 stars 334 forks source link

Server URL is hardcoded all over the place #72

Open dimitrovs opened 8 years ago

dimitrovs commented 8 years ago

If you look at: signup.ts, login.ts, home.ts you see the API URL is hardcoded everywhere:

http://localhost:3001/users http://localhost:3001/sessions/create http://localhost:3001/api/random-quote http://localhost:3001/api/protected/random-quote

You may argue that it doesn't matter, because it's just a "sample" app and users won't be deploying it anywhere, but the truth is hardcoding API URL like this is just bad design. You should have one variable defined in a common place with the API host then use relative paths everywhere else. Otherwise the incentive is too high for the novice user to just replace localhost:3001 with their domain and build a production app with this bad practice. In fact, there already is an issue asking how to do exactly that #52 .

chenkie commented 8 years ago

Hardcoding the URL isn't ideal and you're right, it's just a sample app which is why :)

Want to send a PR to centralize the URL?