I've read this question and my problem seems similar. I have an heroku remote app and I've added the host permission to the manivest v3 of my vue extension.
I need to send a post request from the chrome extension to send notifications, but I'm facing a CORS issue. How I can setup correctly express to use cors? I need to change something in my manifest or chrome extension code?
//express server for heroku fcm extension
const express = require('express')
const app = express()
const axios = require('axios')
const port = process.env.PORT || 3000
const cors = require('cors')({ origin: true })
const serverKey = 'key=AAA...'
//
app.get('/', (req, res) => {
// redirect to chrome web store
res.send('Service Running!')
})
app.post('/sendNotification', (req, res) => {
//cors( (req, res) => {
console.log(req)
const dest = req.body.to
const notification = req.body.notification
axios.post('https://fcm.googleapis.com/fcm/send', {
to: dest,
notification: notification
}, {
headers: {
'Authorization': serverKey,
'Content-Type': 'application/json'
}
}).then( (response) => {
console.log(response)
res.send(response)
})
//})
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
{
"manifest_version": 3,
"name": "push",
"description": "chrome extension",
"version": "1.0",
"background": {
"service_worker": "background.js"
},
"action": {},
"permissions": [
"gcm",
"identity"
],
"host_permissions": [
"https://<...>.herokuapp.com/*"
],
"oauth2": {
"client_id": "...apps.googleusercontent.com",
"scopes": [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"
]
}
}
I'm able to deploy the app on heroku, and when I get the cors issue on the fe I will get a 200 response in server ?