SoUmNerd commited on
Commit
713ecf1
1 Parent(s): 5fdb2d0

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -12
main.py CHANGED
@@ -1,19 +1,14 @@
1
- from fastapi import FastAPI, Request
 
2
 
3
- import subprocess, json
4
  from regex import find_imports
5
 
6
-
7
-
8
-
9
  app = FastAPI()
10
 
11
  @app.post("/code")
12
- async def run_mojo_code(request:Request) -> dict:
13
- data_as_str = await request.json()
14
- print(data_as_str)
15
- print(type(data_as_str))
16
- data = data_as_str
17
  code = data["code"]
18
  filename = data["filename"]
19
 
@@ -24,6 +19,6 @@ async def run_mojo_code(request:Request) -> dict:
24
  with open(filename, "w") as f:
25
  f.write(code)
26
 
27
- return {"sucess":True, "output": subprocess.check_output(["mojo", filename]).decode("utf-8")}, 200
28
  except:
29
- return {"sucess":False}, 500
 
1
+ from fastapi import FastAPI, Request, Response
2
+ from pydantic import BaseModel
3
 
4
+ import subprocess
5
  from regex import find_imports
6
 
 
 
 
7
  app = FastAPI()
8
 
9
  @app.post("/code")
10
+ async def run_mojo_code(request:Request) -> Response:
11
+ data = await request.json()
 
 
 
12
  code = data["code"]
13
  filename = data["filename"]
14
 
 
19
  with open(filename, "w") as f:
20
  f.write(code)
21
 
22
+ return Response(content={"sucess":True, "output": subprocess.check_output(["mojo", filename]).decode("utf-8")}, status_code=200)
23
  except:
24
+ return Response(content={"sucess":False}, status_code=500)