Skip to content

Commit

Permalink
update sandbox_api
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Jan 13, 2024
1 parent 1626e9d commit eee06be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
1 change: 1 addition & 0 deletions examples/sandbox_api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cache/
build/

src/tasks/*.nim
website/

# Garbage
*.exe
Expand Down
22 changes: 0 additions & 22 deletions examples/sandbox_api/Dockerfile

This file was deleted.

20 changes: 19 additions & 1 deletion examples/sandbox_api/src/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ when defined(production):
credentials: true
else:
regCORS:
origins: "http://127.0.0.1:5000"
origins: "*"
headers: "*"
methods: "*"
credentials: true
Expand All @@ -46,6 +46,15 @@ const


serve host, port:
get "/":
{.gcsafe.}:
if not dirExists("website"):
return %*{"response": "website not compiled"}
var f = openAsync("website" / "index.html")
let data = await f.readAll()
f.close()
return data

post "/[task:Task[m]]":
{.gcsafe.}:
if task.code.len > 2048:
Expand Down Expand Up @@ -137,6 +146,15 @@ serve host, port:
for t in tasks:
response.add newJString(t.task.id)

get "/{file:path}":
{.gcsafe.}:
if not dirExists("website"):
return %*{"response": "website not compiled"}
var f = openAsync("website" / file)
let data = await f.readAll()
f.close()
return data

middleware:
{.gcsafe.}:
if req.body.len > 4096:
Expand Down

0 comments on commit eee06be

Please sign in to comment.