I have this code in my service worker file that saves the PushMessage subscription:
var hostURI = window.location.protocol + "//" + window.location.host;
async function saveSubscription(subscription) {
await fetch(hostURI + 'app/saveToken', {
method: 'POST',
mode: 'cors',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
cache: 'default',
body: JSON.stringify(subscription) //PushMessage object
})
.then(response => response.json())
.then(data => console.log(data)); //check response
}
This works fine on my local but on the production server, the backend (PHP) says that the POST data is NULL. This is my test code on the server side:
public function saveToken() {
$postData = (array) $this->request->getPost(); // get all post data
$data['post'] = $postData;
return $this->response->setJSON($data); // return as json
}
For further information, I don't know if this is related but my application is on the sublink so my base url is www.website.com/app.
I'm using CodeIgniter4 and IIS on server side.