android – PWA (progressive web app) with nodejs+expressjs points to /public/ folder at start. How to fix?-ThrowExceptions

Exception or error:

Thanks for checking in 🙂

I am working on making PWA of my web app. My project is yet another nodejs+express set up. It serves public files via node and nginx all good. But when working with PWA all is dancing aroung public folder and routing breaks. So I put manifest.json and service worker js file there, installed my app to desktop and it works fine until I close it. When I fire it up again it points to /public/ folder by default just exposing file folder and nothing else.

In manifest.json: {“start_url”:”/”, “scope”: “/”}. I also tried {“start_url”:”./”, “scope”: “.”} and all known to me relative variations, all the same – points to /public/.

I tried to res.send manifest file via router directly – no good, again points to directory where manifest.json resides.

When I install and open app on my android it just points to /public/ at start.

Have any idea what’s going on here and how to solve it?

Thanks beforehands! 🙂

How to solve:

So I solved it bypassing public folder, putting files to root of project and by sending files directly and it worked:

router.get('/:filename', async function(req, res) {
    if(req.params.filename=='manifest.json'){
        res.sendFile(path.resolve('./manifest.json'))

    } else if(req.params.filename=='service_worker.js'){
        res.sendFile(path.resolve('./service_worker.js'))
    }
})

Leave a Reply

Your email address will not be published. Required fields are marked *