Skip to content

Commit 2e707df

Browse files
chore: CORS permission changed from * to frontend
1 parent f7d35ae commit 2e707df

4 files changed

Lines changed: 10 additions & 12 deletions

File tree

src/backend/auth/github.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async function authenticateAndCreateJWT(
7777

7878
console.log("DB Status for User:", userId, status);
7979

80-
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
80+
8181

8282
if (status.matchedCount == 1 || status.upsertedId !== undefined) {
8383
const id_jwt = await createJWT(provider, userId);
@@ -94,7 +94,6 @@ async function authenticateAndCreateJWT(
9494
}
9595

9696
async function handleJwtAuthentication(ctx: Context) {
97-
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
9897
if (!ctx.request.hasBody) {
9998
ctx.throw(415);
10099
}

src/backend/health-api.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function getContainerHealth(ctx: Context): Promise<void> {
3131

3232
const summary = await getHealthSummary();
3333

34-
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
34+
3535
ctx.response.body = {
3636
total: summary.total,
3737
healthy: summary.healthy,
@@ -68,7 +68,7 @@ export async function getContainerMetrics(ctx: Context): Promise<void> {
6868

6969
const history = await getContainerHistory(subdomain, range);
7070

71-
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
71+
7272
ctx.response.body = {
7373
subdomain,
7474
step: range.step,
@@ -98,7 +98,7 @@ export async function getHealthDashboard(ctx: Context): Promise<void> {
9898
const summary = await getHealthSummary();
9999
const monitorStatus = getMonitorStatus();
100100

101-
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
101+
102102
ctx.response.body = {
103103
overview: {
104104
total: summary.total,
@@ -147,7 +147,7 @@ export async function restartContainerHandler(ctx: Context): Promise<void> {
147147
try {
148148
await restartContainer(subdomain);
149149

150-
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
150+
151151
ctx.response.body = {
152152
status: "success",
153153
message: `Container ${subdomain} restart initiated`,
@@ -183,7 +183,7 @@ export async function stopContainerHandler(ctx: Context): Promise<void> {
183183
try {
184184
await stopContainer(subdomain);
185185

186-
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
186+
187187
ctx.response.body = {
188188
status: "success",
189189
message: `Container ${subdomain} stop initiated`,
@@ -218,7 +218,6 @@ export async function triggerHealthCheckHandler(ctx: Context): Promise<void> {
218218

219219
await triggerHealthCheck();
220220

221-
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
222221
ctx.response.body = {
223222
status: "success",
224223
message: "Health check triggered",

src/backend/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function getSubdomains(ctx: Context) {
1313
ctx.throw(401);
1414
}
1515
const data = await getMaps(author, ADMIN_LIST!);
16-
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
16+
1717
ctx.response.body = data.documents;
1818
}
1919

@@ -44,7 +44,7 @@ async function addSubdomain(ctx: Context) {
4444
ctx.throw(401);
4545
}
4646
const success: boolean = await addMaps(document);
47-
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
47+
4848

4949
if (success) {
5050
await addScript(
@@ -93,7 +93,7 @@ async function deleteSubdomain(ctx: Context) {
9393
"info",
9494
);
9595
}
96-
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
96+
9797
ctx.response.body = data;
9898
}
9999

src/backend/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ router
8080
.post("/health/:subdomain/stop", (ctx) => stopContainerHandler(ctx))
8181
.post("/health/check", (ctx) => triggerHealthCheckHandler(ctx));
8282

83-
app.use(oakCors());
83+
app.use(oakCors({ origin: frontend }));
8484
app.use(router.routes());
8585
app.use(router.allowedMethods());
8686

0 commit comments

Comments
 (0)