Repository: RocketMap/RocketMap

Issue:
Error with JS
Recently I clone the repository and I get this errors:

> map.built.js:227 Uncaught ReferenceError: center_lat is not defined
> 
> map.built.js:1082 Uncaught TypeError: Cannot read property 'setMapTypeId' of undefined
> 
> 19 map.built.js:677 Uncaught TypeError: Cannot read property 'getBounds' of undefined

Error with JS
Recently I clone the repository and I get this errors:

> map.built.js:227 Uncaught ReferenceError: center_lat is not defined
> 
> map.built.js:1082 Uncaught TypeError: Cannot read property 'setMapTypeId' of undefined
> 
> 19 map.built.js:677 Uncaught TypeError: Cannot read property 'getBounds' of undefined



Discussion:
You get those errors from...where?

Why is anything reading `*.built.js` files? Those are an intermediary step...

Also got these from Chrome's console output. No map displays.

Related to #83 and #116?

Edit: Reverting to commit 314c1ac95301ca3ea879e0bfa52796e0406be9c4 fixes the problem for me.
Edit2: ~~Commit 0566c29226a50c19083ac1235ee16a18c2cf13c4 is again broken, so between those two commits is where the errors start happening.~~
Edit 3: Actually the very next commit is where errors start happening. 513a6fc3c97fcc426efc518975fe547ca527297f

Same error here after `git pull`

Fix in issue #116 comments

```
npm install -g grunt
npm install
npm run-script build
```

Can y'all take a screenshot of this? The front end should not be loading any of the `.built.` files.

Sure http://imgur.com/mnHaXG5

@dmunozfer Tried that, doesn't fix the problem for me.

In commit 513a6fc3c97fcc426efc518975fe547ca527297f, center_lat/lng is changed to centerLat/Lng. Wonder if this is why.

I genuinely don't know what to do here. `map.built.js` is not a file that we load. Ever. I have no idea what your browser is picking that up. I can't 100% rule it out as a problem with the project though, so I'll leave this open hoping someone else might have an idea.

I decided to return to the previous version and the problems were solved. Recently I returned to try the latest commit and still coming out the same in the console.

People get `<blah>.built.js` because most moder browsers have javascript source mapping enabled by default and there seems to be something wrong with how the source maps are generated in the grunt file...  it shows `built` for me as well. if i disable js source maps in the dev tools, it says `min` ;)

can't help with that though, i'm a gulp guy

Created #229 regarding source maps issue

@Chlodochar can you take a look at this one? Looks like the lint auto-formatting may have broken something here?

Run `grunt build` and disable your cache.

`center_lat` shouldn't be anywhere in the code anymore. Check the code for yourself. It's `centerLat` now. It's probably a caching problem (HTML is the new version with `centerLat`, but JS is still old version with `center_lat`). Maybe we should do something about caching in Flask.

Not that I doubted you, but grep for `center_lat` indeed returns nothing.

It looks like for me it was indeed caching. Cloudflare was caching the js files. When I connect to the instance directly, map loads. Clear cache on Cloudflare cleared things up.

@miaojs any idea if this can be circumvented from Pokemon Go Map? Is it missing some specific caching headers that cloud flare uses?

Most systems employ some kind of cache buster value, like `url/app.min.js?ts-from-last-build=123456`. Flask probably has something like that...

Just googled it. https://support.cloudflare.com/hc/en-us/articles/202775670-How-Do-I-Tell-CloudFlare-What-to-Cache-

the tl;dr: Cloudflare respects Cache-control header. (time based or no-cache)

@chuyskywalker's solution is probably better since requests between builds can come from cache

I'm working on something, hold tight

You get those errors from...where?

Why is anything reading `*.built.js` files? Those are an intermediary step...

Also got these from Chrome's console output. No map displays.

Related to #83 and #116?

Edit: Reverting to commit 314c1ac95301ca3ea879e0bfa52796e0406be9c4 fixes the problem for me.
Edit2: ~~Commit 0566c29226a50c19083ac1235ee16a18c2cf13c4 is again broken, so between those two commits is where the errors start happening.~~
Edit 3: Actually the very next commit is where errors start happening. 513a6fc3c97fcc426efc518975fe547ca527297f

Same error here after `git pull`

Fix in issue #116 comments

```
npm install -g grunt
npm install
npm run-script build
```

Can y'all take a screenshot of this? The front end should not be loading any of the `.built.` files.

Sure http://imgur.com/mnHaXG5

@dmunozfer Tried that, doesn't fix the problem for me.

In commit 513a6fc3c97fcc426efc518975fe547ca527297f, center_lat/lng is changed to centerLat/Lng. Wonder if this is why.

I genuinely don't know what to do here. `map.built.js` is not a file that we load. Ever. I have no idea what your browser is picking that up. I can't 100% rule it out as a problem with the project though, so I'll leave this open hoping someone else might have an idea.

I decided to return to the previous version and the problems were solved. Recently I returned to try the latest commit and still coming out the same in the console.

People get `<blah>.built.js` because most moder browsers have javascript source mapping enabled by default and there seems to be something wrong with how the source maps are generated in the grunt file...  it shows `built` for me as well. if i disable js source maps in the dev tools, it says `min` ;)

can't help with that though, i'm a gulp guy

Created #229 regarding source maps issue

@Chlodochar can you take a look at this one? Looks like the lint auto-formatting may have broken something here?

Run `grunt build` and disable your cache.

`center_lat` shouldn't be anywhere in the code anymore. Check the code for yourself. It's `centerLat` now. It's probably a caching problem (HTML is the new version with `centerLat`, but JS is still old version with `center_lat`). Maybe we should do something about caching in Flask.

Not that I doubted you, but grep for `center_lat` indeed returns nothing.

It looks like for me it was indeed caching. Cloudflare was caching the js files. When I connect to the instance directly, map loads. Clear cache on Cloudflare cleared things up.

@miaojs any idea if this can be circumvented from Pokemon Go Map? Is it missing some specific caching headers that cloud flare uses?

Most systems employ some kind of cache buster value, like `url/app.min.js?ts-from-last-build=123456`. Flask probably has something like that...

Just googled it. https://support.cloudflare.com/hc/en-us/articles/202775670-How-Do-I-Tell-CloudFlare-What-to-Cache-

the tl;dr: Cloudflare respects Cache-control header. (time based or no-cache)

@chuyskywalker's solution is probably better since requests between builds can come from cache

I'm working on something, hold tight


Resolving patch:
diff --git a/runserver.py b/runserver.py
--- a/runserver.py
+++ b/runserver.py
@@ -41,6 +41,7 @@
 from threading import Thread, Event
 from queue import Queue
 from flask_cors import CORS
+from flask.ext import cache_bust
 
 from pogom import config
 from pogom.app import Pogom
@@ -162,6 +163,9 @@
     if args.cors:
         CORS(app);
 
+    # No more stale JS
+    cache_bust.init_cache_busting(app)
+
     app.set_search_control(pause_bit)
     app.set_location_queue(new_location_queue)
 


Test patch: