Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a PWA application with push notification functionality. I am still new to this and have just recently added the push functionality into my app. I am referring to Get started with Progressive Web Apps - Microsoft Edge Development | Microsoft Docs[^] for my learning step.
I tried to run the app in Chrome and i encountered the error as same as title above in F12 development tools. Full error is as below:
POST http://localhost:portNumber/register 405 (Method Not Allowed)
.
I have install the web-push library as guided by the link above and have the following codes in the index.js file provided by the library installed:
router.post('/register', function (req, res) {
    // A real world application would store the subscription info.
    res.sendStatus(201);
});


At first i thought the codes in above link only support Edge but i do not think this is the case here as the following codes is executed after a promise is returned:
navigator.serviceWorker.ready
    .then(function (registration) {
        //do something with VAPID keys
    }).then(function (subscription) {
        // Send the subscription details to the server
        fetch('./register', { //error occurs here
            method: 'post',
            headers: {
                'Content-type': 'application/json'
            },
            body: JSON.stringify({
                subscription: subscription
            }),
        });


What I have tried:

1. Change the script by referring to another source but to no avail.
2. Search online for error 405 solution seems to be permission issue but could not pinpoint a root cause here.
3. Thought is path issue but in fetch('./register') but this is not the case.
Posted
Comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900