Merge pull request #1696 from Shirtiny/master

Supports the configuration of   `Access-Control-Allow-Origin`  through environment variables.
This commit is contained in:
binaryify 2023-02-16 14:28:04 +08:00 committed by GitHub
commit 03fab7f2d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -133,6 +133,7 @@ async function checkVersion() {
*/ */
async function consturctServer(moduleDefs) { async function consturctServer(moduleDefs) {
const app = express() const app = express()
const { CORS_ALLOW_ORIGIN } = process.env
app.set('trust proxy', true) app.set('trust proxy', true)
/** /**
@ -142,7 +143,8 @@ async function consturctServer(moduleDefs) {
if (req.path !== '/' && !req.path.includes('.')) { if (req.path !== '/' && !req.path.includes('.')) {
res.set({ res.set({
'Access-Control-Allow-Credentials': true, 'Access-Control-Allow-Credentials': true,
'Access-Control-Allow-Origin': req.headers.origin || '*', 'Access-Control-Allow-Origin':
CORS_ALLOW_ORIGIN || req.headers.origin || '*',
'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type', 'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type',
'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS', 'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS',
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',