feat: allow cors

This commit is contained in:
Anton Voylenko 2026-01-11 15:02:26 +02:00
commit 44c14bb324
4 changed files with 36 additions and 2 deletions

View file

@ -51,4 +51,8 @@ ENABLE_SWAGGER_ENDPOINT=TRUE
# OPTIONAL, BASE PATH FOR MOUNTING ROUTES (e.g., /api/v1/whatsapp) # OPTIONAL, BASE PATH FOR MOUNTING ROUTES (e.g., /api/v1/whatsapp)
BASE_PATH= BASE_PATH=
# OPTIONAL, ENABLE WHEN BEHIND REVERSE PROXY/LOAD BALANCER # 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
View file

@ -10,6 +10,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^1.13.2", "axios": "^1.13.2",
"cors": "^2.8.5",
"dotenv": "^16.6.1", "dotenv": "^16.6.1",
"express": "^4.22.1", "express": "^4.22.1",
"express-rate-limit": "^7.5.1", "express-rate-limit": "^7.5.1",
@ -31,7 +32,7 @@
"swagger-autogen": "^2.23.7" "swagger-autogen": "^2.23.7"
}, },
"engines": { "engines": {
"node": ">=18" "node": ">=20"
} }
}, },
"node_modules/@ampproject/remapping": { "node_modules/@ampproject/remapping": {
@ -2601,6 +2602,19 @@
"license": "MIT", "license": "MIT",
"optional": true "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": { "node_modules/cosmiconfig": {
"version": "9.0.0", "version": "9.0.0",
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-9.0.0.tgz", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-9.0.0.tgz",
@ -6411,6 +6425,15 @@
"node": ">=8" "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": { "node_modules/object-inspect": {
"version": "1.13.3", "version": "1.13.3",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.3.tgz", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.3.tgz",

View file

@ -10,6 +10,7 @@
}, },
"dependencies": { "dependencies": {
"axios": "^1.13.2", "axios": "^1.13.2",
"cors": "^2.8.5",
"dotenv": "^16.6.1", "dotenv": "^16.6.1",
"express": "^4.22.1", "express": "^4.22.1",
"express-rate-limit": "^7.5.1", "express-rate-limit": "^7.5.1",

View file

@ -1,5 +1,6 @@
require('./routes') require('./routes')
const express = require('express') const express = require('express')
const cors = require('cors')
const { routes } = require('./routes') const { routes } = require('./routes')
const { maxAttachmentSize, basePath, trustProxy } = require('./config') const { maxAttachmentSize, basePath, trustProxy } = require('./config')
@ -16,6 +17,11 @@ if (trustProxy) {
app.use(express.json({ limit: maxAttachmentSize + 1000000 })) app.use(express.json({ limit: maxAttachmentSize + 1000000 }))
app.use(express.urlencoded({ limit: maxAttachmentSize + 1000000, extended: true })) 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 // Mount routes with configurable base path
app.use(basePath, routes) app.use(basePath, routes)