whatsapp-api-nodejs icon indicating copy to clipboard operation
whatsapp-api-nodejs copied to clipboard

Is it possible to place a white list for the CROS to work?

Open rodrigoaballay opened this issue 1 year ago • 2 comments

I need to activate the CROS and if possible make a white list to be able to only have access from my server to another. The problem to solve would be this : Access to XMLHttpRequest at 'Server 1' from origin 'Server 2' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource .

It is my first time using all this environment, I await your answers

rodrigoaballay avatar Aug 01 '22 14:08 rodrigoaballay

Express docs about cors middleware is very detailed https://expressjs.com/en/resources/middleware/cors.html

salman0ansari avatar Aug 02 '22 16:08 salman0ansari

I came for the same request, do this in src/api/routes/index.js:

const express = require('express')
const router = express.Router()
const instanceRoutes = require('./instance.route')
const messageRoutes = require('./message.route')
const miscRoutes = require('./misc.route')
const groupRoutes = require('./group.route')
const cors = require('cors');

router.get('/status', cors(), (req, res) => res.send('OK'))
router.use('/instance', cors(), instanceRoutes)
router.use('/message', cors(), messageRoutes)
router.use('/group', cors(), groupRoutes)
router.use('/misc', cors(), miscRoutes)

module.exports = router

I appreciate it if this could added as an optional procedure to this repo.

tinyCoder32 avatar Aug 05 '22 15:08 tinyCoder32

I came for the same request, do this in src/api/routes/index.js:

const express = require('express')
const router = express.Router()
const instanceRoutes = require('./instance.route')
const messageRoutes = require('./message.route')
const miscRoutes = require('./misc.route')
const groupRoutes = require('./group.route')
const cors = require('cors');

router.get('/status', cors(), (req, res) => res.send('OK'))
router.use('/instance', cors(), instanceRoutes)
router.use('/message', cors(), messageRoutes)
router.use('/group', cors(), groupRoutes)
router.use('/misc', cors(), miscRoutes)

module.exports = router

I appreciate it if this could be added as an optional procedure to this repo.

feel free to fork and make changes to your like.

salman0ansari avatar Aug 20 '22 18:08 salman0ansari