I am trying to implement Push Notifications in my Python Django App.
Project Structure:
.
├── db.sqlite3
├── manage.py
├── example
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── wsgi.py
├── README.md
├── requirements.txt
├── static
│ ├── js
│ ├── sw.js
│ ├── push.js
└── templates
└── landing
├── homepage.html
Now,
Homepage.html file includes a script
<script src="{% static 'js/push.js' %}"></script>
Push.js includes:
navigator.serviceWorker.register('../static/js/sw.js').then(function(serviceWorkerRegistration) {
And let's say the this webApp is hosted on www.example.com.
Now, I have two queries:
1) I can access the file at www.example.com/static/js/sw.js, But not on www.example.com/sw.js. If I move sw.js file at the root directory, and try www.example.com/sw.js then I get the following Error:
Using the URLconf defined in example.urls, Django tried these URL patterns, in this order: (and followed by a llist of urls mentioned in urls.py)
Also, If i run 'python manage.py collectstatic' command then the file sw.js automatically gets moved to static/js/sw.js only. So, How can I make www.example.com/sw.js work ?
2) Can it be possible to host sw.js on Google Storage Bucket/AWS Bucket/somewhere else and fetch this file from there ? ( Or Can absolute path of the file hosted on remote server be used )
Tried to google this query but couldn't find the satisfactory answer for these issues.
Any suggestions would be useful.
Thanks,