0

Currently its Angular 5

I have made an application in angular 5, now that I have logged in and came to the dashboard inside, I turned off my angular server, but backend(nodejs) server is still on. When I click on a link, which is a child angular route(routerLink/router-outlet) inside that dashboard, it still goes to that route. WHAT IS HAPPENING?? I thought that angular server is off, so nothing should happen, but its properly working(other than rendering some external javascript). Moreover, its also fetching data from backend!!!

Previously I thought that, when I click on a child route, the child view will come from the angular server, then renders and fetches data from backend, but its like its sending the complete Angular application on browser once its url hits on browser for the first time. I am totally confused!! I still think that this shouldn't have happened but it is!

Can somebody please explain what is happening?? Isn't it against application security!?

Ankur Shah
  • 801
  • 1
  • 12
  • 26
  • `I turned off my angular server, but backend(nodejs) server is still on`, you mean you have _two_ servers for delivering your site? If so, one of them is useless (and not being used). – Jeremy Thille Dec 01 '17 at 10:18
  • @JeremyThille: Yes off course! But is it angular philosophy to send the complete angular app in just one url hit on browser address bar?? Here, '_Complete Angular App_' means all the views included in child-routes and other routes! – Ankur Shah Dec 01 '17 at 10:51
  • 1
    `Yes of course` what? Yes of course you have two servers? Well no, you shouldn't :) Why have two servers for an app? One is necessarily not in use. `But is it angular philosophy to send the complete angular app in just one url ` Not if you have lazy-loaded modules, then Angulars loads different `chunk_xxx.js` when needed. – Jeremy Thille Dec 01 '17 at 11:01
  • @JeremyThille: Ok I explain! My angular code(`localhost:4200`) and nodejs code(`localhost:4444`) are on different folders(assume in folders of different drives)! So the servers are being used separately (`npm start` for each one) ! And this is the way we use angular with nodejs! Now that I have stopped the server for angular part in the middle, it should have stopped getting views/components from angular folder, but this isn't happening, instead, its getting the views on clicks, with proper request handing to backend. And it seems that its having all of the views there(in browser) already! – Ankur Shah Dec 01 '17 at 11:13
  • @JeremyThille: Actually I was thinking of securing the front-end server that when someone clicks on the `routerLink` url, it confirms the token value and then bring the view required, when logged in! But you know what is happening! – Ankur Shah Dec 01 '17 at 11:18
  • @JeremyThille: Why are you saying I shouldn't have used two servers? Is there a different/more probable approach than what I have said above? – Ankur Shah Dec 01 '17 at 11:28
  • Well, when you don't have your own Node server, then ng-cli provides a built-in one, that you can launch with `ng serve`. It's handy. But as soon as you make your own Node server like you did, then `ng serve` becomes useless. You _can_ very well launch both servers at the same time on two different ports, like you did, but it's useless. You will only use one anyway (you will access your site using `localhost:4200` OR `localhost:4444`, not both at once :) Besides, how do you intend to run `ng serve` on a production server?? It's a handy developement feature, nothing more. – Jeremy Thille Dec 01 '17 at 12:29
  • @JeremyThille: Oh sir! `npm start` command uses `ng serve` internally! Check the package.json! I was using this ng-cli the whole time, and it is a server which is initiating angular part, about which I was talking that I turned it off in the middle! Don't you count it as a different server than the backend?? – Ankur Shah Dec 01 '17 at 12:57
  • Uh, honestly I'm getting lost. All I know is that having two servers (one on 4200, one on 4444) is useless and counter-productive. Just use one server. – Jeremy Thille Dec 01 '17 at 13:00
  • @JeremyThille: Its Ok sir! Btw, thanks for the term **Lazy-Loading**, I think that is what I needed ! :) – Ankur Shah Dec 01 '17 at 13:10

0 Answers0