Angular2 Behind Proxy

125 views
Skip to first unread message

William Davis

unread,
Jun 28, 2016, 8:20:46 AM6/28/16
to AngularJS
I may have looked over something obvious, but I am having trouble getting my angular2 app to work through a proxy. To my understanding I have to hardcode the base href for the app and the router to work, this seems problematic when the base url can change if I am going through a proxy. For example, if I host my app at http://mysite.com/ng2-app/ and then proxy to http://mysite.com/public/app/ I get an error in the browser console: 
Cannot match any routes. Current segment: 'public'. Available routes: ['/sample', '/request-form', '/', '/request-view'].

Is there a way to make the app relative to their root URL and never hardcode the root? Am I misunderstanding how something works or overlooking something?

Lucas Lacroix

unread,
Jun 28, 2016, 9:05:59 AM6/28/16
to ang...@googlegroups.com
I don't like this "quirk" either. Really, the "<base>" element is configuration, whereas your HTML is an application that should be able to run anywhere. But... I also don't see a way around this. It's part of the reason I also prefer the HashLocationStrategy over the default strategy.

You should not have an issue if access is always through the proxy. The base element should reference the proxied URL.

You may be able to do something on your webserver by rewriting the HTML dynamically to put the correct href value, but that may be difficult and it only makes sense when you know all the possible mappings for your application.

-Luke

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Lucas Lacroix
Computer Scientist
System Technology Division, MEDITECH
Reply all
Reply to author
Forward
0 new messages