feat: allow to override CORS origins using environment variable

This commit is contained in:
Siyuan Miao 2025-02-11 13:45:46 +01:00
parent ae4bc804c2
commit 954303afa5
2 changed files with 7 additions and 1 deletions

View File

@ -16,3 +16,5 @@ R2_ACCESS_KEY_ID=XXX # Any S3 compatible access key
R2_SECRET_ACCESS_KEY=XXX # Any S3 compatible secret access key
R2_BUCKET=XXX # Any S3 compatible bucket
R2_CDN_URL=XXX # Any S3 compatible CDN URL
CORS_ORIGINS=https://app.jetkvm.com,http://localhost:5173 # Allowed CORS Origins, split by comma

View File

@ -36,6 +36,8 @@ declare global {
R2_SECRET_ACCESS_KEY: string;
R2_BUCKET: string;
R2_CDN_URL: string;
CORS_ORIGINS: string;
}
}
}
@ -48,7 +50,9 @@ app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(
cors({
origin: ["https://app.jetkvm.com", "http://localhost:5173"],
origin: process.env.CORS_ORIGINS?.split(",") || [
"https://app.jetkvm.com", "http://localhost:5173"
],
credentials: true,
}),
);