Skip to content

Commit 0eb8fe0

Browse files
authored
Merge pull request #51 from zacharyLYH/dev
Revert API routes to use dynamic base URL
2 parents 28f78f1 + 03ea102 commit 0eb8fe0

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

app/api/code/score/route.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,16 @@ export async function POST(req: Request) {
8383
} else {
8484
score = "58";
8585
}
86-
86+
// Extract the host and protocol from the incoming request
87+
const url = new URL(req.url);
88+
const baseUrl = `${url.protocol}//${url.host}`;
8789
console.log(
8890
"ABOUT TO SEND RESULT ",
8991
score,
9092
"to",
91-
"https://" + process.env.VERCEL_URL + `/api/feedback/result`
93+
`${baseUrl}/api/feedback/result`
9294
);
93-
axios.post("https://" + process.env.VERCEL_URL + `/api/feedback/result`, {
95+
axios.post(`${baseUrl}/api/feedback/result`, {
9496
score,
9597
challenge,
9698
code,

app/api/code/submit/route.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,14 @@ export async function POST(req: Request) {
7676
lastSubmission: new Date().toISOString(),
7777
});
7878
}
79-
80-
console.log("BASE URL: ", "https://" + process.env.VERCEL_URL);
79+
// Extract the host and protocol from the incoming request
80+
const url = new URL(req.url);
81+
const baseUrl = `${url.protocol}//${url.host}`;
82+
console.log("BASE URL: ", baseUrl);
8183
// Use the base URL for Axios requests
82-
axios.put(
83-
"https://" + process.env.VERCEL_URL + `/api/increment/submit`,
84-
{}
85-
);
84+
axios.put(`${baseUrl}/api/increment/submit`, {});
8685

87-
axios.post(
88-
"https://" + process.env.VERCEL_URL + `/api/code/score`,
89-
body
90-
);
86+
axios.post(`${baseUrl}/api/code/score`, body);
9187

9288
return NextResponse.json({ message: "Accepted" }, { status: 202 });
9389
} catch (error) {

0 commit comments

Comments
 (0)