Skip to content

Commit 9f341c6

Browse files
committed
Add code execution service to api gateway
1 parent 61f0757 commit 9f341c6

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

api_gateway/src/proxy/routes_config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { collabServiceHostUrl, matchServiceHostUrl, questionServiceUrl, userServiceHostUrl } from "./service_addresses";
1+
import { collabServiceHostUrl, executionServiceHostUrl, matchServiceHostUrl, questionServiceUrl, userServiceHostUrl } from "./service_addresses";
22

33
export const routes_config = [
44
{
@@ -15,6 +15,13 @@ export const routes_config = [
1515
changeOrigin: true
1616
}
1717
},
18+
{
19+
url: "/api/code",
20+
proxy: {
21+
target: executionServiceHostUrl,
22+
changeOrigin: true
23+
}
24+
},
1825
{
1926
url: "/auth",
2027
proxy: {

api_gateway/src/proxy/service_addresses.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export const isLocal = process.env.ENV_TYPE !== "docker";
44
export const questionServiceUrl = isLocal ? "http://localhost:8080" : "http://question-service:8080/";
55
export const userServiceHostUrl = isLocal ? "http://localhost:8081" : "http://user-service:8081/";
66
export const matchServiceHostUrl = isLocal ? "http://localhost:8082" : "http://matching-service:8082"
7-
export const collabServiceHostUrl = isLocal ? "http://localhost:8083" : "http://collab-service:8083"
7+
export const collabServiceHostUrl = isLocal ? "http://localhost:8083" : "http://collab-service:8083"
8+
export const executionServiceHostUrl = isLocal ? "http://localhost:8090" : "http://code-execution:8090";

docker_compose_dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ services:
4747
- profile_pictures:/usr/src/app/public/profile_pictures
4848

4949
code-execution:
50+
container_name: code-execution
5051
build:
5152
context: ./code_execution
5253
environment:

frontend/src/api/code.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { apiGatewayClient } from "./gateway";
2+
3+
export async function submitCodeForExecution(data_payload: any) {
4+
const res = await apiGatewayClient.post("/api/code/submit", data_payload);
5+
6+
return res;
7+
}
8+
9+
export async function getExecutionResult(token : string) {
10+
const res = await apiGatewayClient.post(`/api/code/result/${token}`);
11+
12+
return res;
13+
}

frontend/src/contexts/sharededitor.context.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { Buffer } from "buffer";
1818
import data from "../data/lang_temps.json";
1919
import { ToastId, useToast } from "@chakra-ui/react";
2020
import { wsCollabUrl } from "../api/gateway";
21-
import { executionServiceClient } from "../api/server";
21+
import { getExecutionResult, submitCodeForExecution } from "../api/code";
2222

2323
export type language = keyof typeof data;
2424

@@ -146,17 +146,18 @@ export const SharedEditorProvider = ({
146146
const submitToServer = async (submission: submissionRecord) => {
147147
// curr submission and currsubmission in state should alr be submitted
148148
console.log("submitting answer to server");
149-
const res = await executionServiceClient.post("/api/code/submit", {
149+
const res = await submitCodeForExecution({
150150
lang: submission.lang,
151151
source_code: submission.code,
152152
qn__id: submission.qn_id,
153153
uid: submission.user,
154-
});
154+
})
155+
155156
const token = res.data.token as string;
156157

157158
_states.current?.set(TOKEN_STATE, token);
158159
_poll_interval.current = setInterval(async () => {
159-
const res = await executionServiceClient.get(`/api/code/result/${token}`);
160+
const res = await getExecutionResult(token);
160161
const result = res.data as SubmissionResult;
161162
_states.current?.set(SUBMISSION_RESULT_STATE, result);
162163
if (result.completed) {

0 commit comments

Comments
 (0)