Ember CLI and browser refresh (F5)


#1

Hi everybody,

I am probably not the first who asks this question, but I still cannot find a solution.

An Ember application is based on:

- Ember CLI 0.2.0-beta.1
- Ember 1.10.0
- Ember Simple Auth 0.8.0-beta.3

The application is deployed on a Tomcat server. When a user traverses through application pages, browser URL changes itself based on defined application routes. If at some moment the application is in a route, let’s say, http://my-domain/my-app/one/two/three and a user does browser refresh (F5), then the Tomcat (and not Ember application itself) tries to find the path one/two/three in the deployed web application and obviously a user gets an error.

I found some advises to set the locationType property to hash in Ember CLI config (it was auto by my side). But the problem does not get resolved with it, and in addition the Ember Simple Auth stops to work.

Has anyone had a positive experience with browser refresh for an Ember CLI application?

Thank you!


#2

On Jun 22, 2015, at 8:03 AM, adry1 noreply@emberjs.com wrote:


#3

This isn’t an Ember problem at all. Tomcat isn’t serving your my-app/index.html in /my-app/one/two/three and you are reaching in a server 404 error.

I don’t know much about Tomcat except by using it once or twice, but you could probably find some way to use some sort of URL rewriting to point all URLs (except static files) to my-app/index.html.


#4

I found some advises to set the locationType property to hash in Ember CLI config (it was auto by my side). But the problem does not get resolved with it, and in addition the Ember Simple Auth stops to work.

I’ve had the same problem as you and this solved it for me. I’m using Simple Auth as well, so Ember doesn’t seem to be the problem.


#5

One of the problems for newcomers with Ember.js is that error messages during transitions, by default, sort of get swallowed. (By the time an error is logged, it’s not the original error.) And of course, in a new environment making sense of errors is something that takes a while to learn. But I thought I’d share something from “the other side”, just for amusement.

I tried to log into iTunes Connect (Apple’s site for those who publish software on their App Stores) this morning, and, as it occasionally does, the page was totally blank. Unusually, it won’t display after a refresh. So what the heck, I decide to open the dev console and take a look. Sure enough, a Javascript error! And, the error message, to me at least, is an absolute classic:

Error: [$injector:modulerr] http://errors.angularjs.org/1.2.16/$injector/modulerr?p0=vs-repeat&p1=[%24injector%3Anomod]%20http%3A%2F%2Ferrors.angularjs.org%2F1.2.16%2F%24injector%2Fnomod%3Fp0%3Dvs-repeat https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F19feaea7c072b43b3e28ab8827200619%2Fitc%2Fjs%2Fcompiled%2Flib%2Fvendor.js%3A23%3A455 https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F19feaea7c072b43b3e28ab8827200619%2Fitc%2Fjs%2Fcompiled%2Flib%2Fvendor.js%3A37%3A261 https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F19feaea7c072b43b3e28ab8827200619%2Fitc%2Fjs%2Fcompiled%2Flib%2Fvendor.js%3A38%3A262 https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F19feaea7c072b43b3e28ab8827200619%2Fitc%2Fjs%2Fcompiled%2Flib%2Fvendor.js%3A50%3A3 forEach%40[native%20code] q%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F19feaea7c072b43b3e28ab8827200619%2Fitc%2Fjs%2Fcompiled%2Flib%2Fvendor.js%3A24%3A287 e%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F19feaea7c072b43b3e28ab8827200619%2Fitc%2Fjs%2Fcompiled%2Flib%2Fvendor.js%3A49%3A446 ac%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F19feaea7c072b43b3e28ab8827200619%2Fitc%2Fjs%2Fcompiled%2Flib%2Fvendor.js%3A53%3A35 c%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F19feaea7c072b43b3e28ab8827200619%2Fitc%2Fjs%2Fcompiled%2Flib%2Fvendor.js%3A34%3A433 %24b%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F19feaea7c072b43b3e28ab8827200619%2Fitc%2Fjs%2Fcompiled%2Flib%2Fvendor.js%3A35%3A141 https%3A%2F%2Fitunesconnect.apple.com%2FWebObjects%2FiTunesConnect.woa%2Fra%2Fcommon%2FrequireJsMain%3Fnoext%3A89%3A22 execCb%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A13600 check%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A7732 https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A10023 https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A814 https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A10403 each%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A283 emit%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A10374 check%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A8229 https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A10023 https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A814 https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A10403 each%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A283 emit%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A10374 check%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A8229 enable%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A10273 init%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A6837 o%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A5413 completeLoad%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A12843 onScriptLoad%40https%3A%2F%2Fitunesconnect.apple.com%2Fc%2F9b71c97471abf1ea7079f1f675569ea1%2Fitc%2Fjs%2Fcompiled%2Flib%2Frequire.min.js%3A5%3A13762

I think I prefer Ember’s error messages :wink:

Granted, parts of that look like a stack trace, expressed as a path, and URL-encoded. Maybe. But the long strings of hex digits???


#6

@adr1 I got around this issue (using a CakePHP backend) by creating a custom DispatcherFilter that checks whether the request is XHR and wasn’t for the main index. If both tests are negative, the request is changed to serve the main index. Importantly, I’m not redirecting the request, just changing what will serve it. Ember then “sees” what the actual request is and loads the appropriate route.

It’s been awhile (~10 years!) since i poked around in Tomcat’s xml configs but I’m pretty sure you could do something similar.

@sribe Nice! Those hex sequences look like an md5 hash; probably a version string