feat: allow cors
This commit is contained in:
parent
65add03cbc
commit
44c14bb324
4 changed files with 36 additions and 2 deletions
|
|
@ -51,4 +51,8 @@ ENABLE_SWAGGER_ENDPOINT=TRUE
|
|||
# OPTIONAL, BASE PATH FOR MOUNTING ROUTES (e.g., /api/v1/whatsapp)
|
||||
BASE_PATH=
|
||||
# OPTIONAL, ENABLE WHEN BEHIND REVERSE PROXY/LOAD BALANCER
|
||||
TRUST_PROXY=FALSE
|
||||
TRUST_PROXY=FALSE
|
||||
|
||||
## CORS ##
|
||||
# OPTIONAL, CORS ALLOWED ORIGINS (comma separated), DEFAULT ALLOWS ALL
|
||||
# ALLOWED_ORIGINS=http://localhost:3000,http://example.com
|
||||
25
package-lock.json
generated
25
package-lock.json
generated
|
|
@ -10,6 +10,7 @@
|
|||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "^1.13.2",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.6.1",
|
||||
"express": "^4.22.1",
|
||||
"express-rate-limit": "^7.5.1",
|
||||
|
|
@ -31,7 +32,7 @@
|
|||
"swagger-autogen": "^2.23.7"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@ampproject/remapping": {
|
||||
|
|
@ -2601,6 +2602,19 @@
|
|||
"license": "MIT",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/cors": {
|
||||
"version": "2.8.5",
|
||||
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"object-assign": "^4",
|
||||
"vary": "^1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/cosmiconfig": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-9.0.0.tgz",
|
||||
|
|
@ -6411,6 +6425,15 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/object-assign": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/object-inspect": {
|
||||
"version": "1.13.3",
|
||||
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.3.tgz",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.13.2",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.6.1",
|
||||
"express": "^4.22.1",
|
||||
"express-rate-limit": "^7.5.1",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
require('./routes')
|
||||
const express = require('express')
|
||||
const cors = require('cors')
|
||||
const { routes } = require('./routes')
|
||||
const { maxAttachmentSize, basePath, trustProxy } = require('./config')
|
||||
|
||||
|
|
@ -16,6 +17,11 @@ if (trustProxy) {
|
|||
app.use(express.json({ limit: maxAttachmentSize + 1000000 }))
|
||||
app.use(express.urlencoded({ limit: maxAttachmentSize + 1000000, extended: true }))
|
||||
|
||||
app.use(cors({
|
||||
origin: process.env.ALLOWED_ORIGINS?.split(',') || '*',
|
||||
credentials: true
|
||||
}))
|
||||
|
||||
// Mount routes with configurable base path
|
||||
app.use(basePath, routes)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue