Skip to content

Commit 956fa9a

Browse files
[fixed 🐱‍🏍] fixed internal server issue & add default view pages 🎉
1 parent 1653e52 commit 956fa9a

8 files changed

Lines changed: 145 additions & 16 deletions

File tree

app.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,20 @@ app.post("/run", async (req, res) => {
100100
}
101101
});
102102

103-
const PORT = process.env.PORT || 5000;
103+
app.get(["/", "/index", "/index.html"], (_, res) => {
104+
res.sendFile(path.join(process.cwd(), "./", "views", "index.html"));
105+
});
106+
app.use((req, res) => {
107+
res.status(404);
108+
if (req.accepts("html")) {
109+
res.sendFile(path.join(process.cwd(), "./", "views", "404.html"));
110+
} else if (req.accepts("json")) {
111+
res.json({ message: "404 Not found" });
112+
} else {
113+
res.type("txt").send("404 not found");
114+
}
115+
});
116+
const PORT = process.env.PORT || 6000;
104117
app.listen(PORT, () => {
105118
console.log(`Code executor backend listening on port ${PORT}`);
106119
});

views/404.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>404 not found</title>
8+
</head>
9+
<style>
10+
@import url("https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap");
11+
12+
* {
13+
margin: 0;
14+
padding: 0;
15+
box-sizing: border-box;
16+
}
17+
18+
html {
19+
font-family: "Share Tech Mono", monospace;
20+
font-size: 2.5rem;
21+
}
22+
23+
body {
24+
min-height: 100vh;
25+
background-color: #000;
26+
color: whitesmoke;
27+
display: grid;
28+
place-content: center;
29+
padding: 1rem;
30+
}
31+
p,
32+
a {
33+
text-align: center;
34+
margin-top: 0.5rem;
35+
font-size: 0.8rem;
36+
text-decoration: none;
37+
}
38+
39+
a {
40+
color: green;
41+
}
42+
</style>
43+
<body>
44+
<h1>Sorry!</h1>
45+
<p>The resource you have reqested does not exist.</p>
46+
</body>
47+
</html>

views/index.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<link
8+
rel="shortcut icon"
9+
href="https://avatars.githubusercontent.com/u/82939905?size=100&v=4&rounded=true"
10+
type="image/x-icon"
11+
/>
12+
<title>ExecuteMe - API</title>
13+
</head>
14+
<style>
15+
@import url("https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap");
16+
17+
* {
18+
margin: 0;
19+
padding: 0;
20+
box-sizing: border-box;
21+
}
22+
23+
html {
24+
font-family: "Share Tech Mono", monospace;
25+
font-size: 2.5rem;
26+
}
27+
28+
body {
29+
min-height: 100vh;
30+
background-color: #000;
31+
color: whitesmoke;
32+
display: grid;
33+
place-content: center;
34+
padding: 1rem;
35+
}
36+
p,
37+
a {
38+
text-align: center;
39+
margin-top: 0.5rem;
40+
font-size: 0.8rem;
41+
text-decoration: none;
42+
}
43+
44+
a {
45+
color: green;
46+
}
47+
</style>
48+
<body>
49+
<h1>Code Executor Engine</h1>
50+
<p>
51+
Created by:
52+
<a href="https://devlopersabbir.github.io">Sabbir Hossain</a>
53+
</p>
54+
</body>
55+
</html>

websites/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SERVER_BASE_URL="http://localhost:6000"

websites/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ yarn-error.log*
3131
.pnpm-debug.log*
3232

3333
# env files (can opt-in for committing if needed)
34-
.env*
34+
.env
3535

3636
# vercel
3737
.vercel

websites/src/app/_actions/execute.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,44 @@ type Input = {
99
language: Language;
1010
code: string;
1111
};
12+
1213
type Output = {
1314
output: string;
1415
responseTime: number; // in milliseconds
1516
};
17+
1618
export async function executeCodeAction(input: Input): Promise<Output> {
1719
const start = performance.now();
18-
let responseTime = 0;
19-
let end = 0;
20+
2021
try {
2122
const response = await axios.post(`${baseUri}/run`, input);
22-
end = performance.now();
23-
responseTime = end - start;
23+
const end = performance.now();
2424

2525
return {
2626
output: response.data.output,
27-
responseTime: Math.round(responseTime),
27+
responseTime: Math.round(end - start),
2828
};
29-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3029
} catch (error: any) {
31-
end = performance.now();
32-
responseTime = end - start;
30+
const end = performance.now();
31+
const responseTime = Math.round(end - start);
3332

34-
const errorMessage = error.response.data.details as unknown as string;
35-
const response = {
36-
output: errorMessage,
37-
responseTime: Math.round(responseTime),
38-
};
39-
throw new Error(JSON.stringify(response));
33+
// Safer extraction of error message
34+
const errorMessage =
35+
error?.response?.data?.details || "Unknown error occurred";
36+
37+
// Optional: log more useful error info for debugging
38+
console.error("executeCodeAction Error:", {
39+
message: errorMessage,
40+
status: error?.response?.status,
41+
data: error?.response?.data,
42+
});
43+
44+
// Throw a serializable error object
45+
throw new Error(
46+
JSON.stringify({
47+
output: errorMessage,
48+
responseTime,
49+
})
50+
);
4051
}
4152
}

websites/src/app/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default function ExecuteMePlatform() {
5555
});
5656
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5757
} catch (err: any) {
58+
console.log(err);
5859
const error = JSON.parse(err.message);
5960
setExecutionResult({
6061
status: "error",

websites/src/constants/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export const baseUri =
22
process.env.NODE_ENV !== "development"
33
? process.env.SERVER_BASE_URL
44
: "http://localhost:6000";
5+
// export const baseUri = "http://145.223.97.55:6000";

0 commit comments

Comments
 (0)