I am new to flask and building my first web app. My service worker registers fine when running from localhost, but when I deploy the app to pythonanywhere. To build this, followed the process on www.flaskpwa.com. Here is what I got:
My sw.js file is located in the static folder.
I have a route to serve the service worker js file:
@app.route('/sw.js') def sw(): return app.send_static_file('sw.js')
On my PythonAnywhere "Web" page, I have a Static Files path called /static/ pointing to the static folder.
My app.js file is registering the service worker using:
navigator.serviceWorker.register('./sw.js')
When loading my web app, my console is returning the following two errors:
A bad HTTP response code (404) was received when fetching the script.
Unable to register service worker. TypeError: Failed to register a ServiceWorker for scope ('https://xxxxx.pythonanywhere.com/') with script ('https://xxxxx.pythonanywhere.com/sw.js'): A bad HTTP response code (404) was received when fetching the script.
I am pretty sure my issue is with the Flask route, since I get the same 404 error when attempting to point to xxxxx.pythonanywhere.com/sw.js from the browser. I am stuck in trying to get that correct.
Thanks for your input.