Last active
December 30, 2020 21:48
-
-
Save prasmussen/5b1e2a42b295316dd8b1f665fa8589a7 to your computer and use it in GitHub Desktop.
Code sandbox tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 8000; | |
server_name _; | |
root /home/glot/www; | |
index index.html; | |
location / { | |
try_files $uri $uri/ =404; | |
} | |
# Proxy requests to docker-run | |
location /run { | |
proxy_pass http://localhost:8088/run; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Code sandbox</title> | |
<style> | |
textarea { | |
width: 80vw; | |
height: 30vh; | |
display: block; | |
margin-bottom: 20px; | |
} | |
button { | |
padding: 10px; | |
width: 100px; | |
margin: auto; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="content"> | |
<textarea id="code" placeholder="Code">print("Hello World")</textarea> | |
<textarea id="result" placeholder="Output"></textarea> | |
<button id="run" type="button">Run</button> | |
</div> | |
<script> | |
const runElem = document.getElementById('run'); | |
const codeElem = document.getElementById('code'); | |
const resultElem = document.getElementById('result'); | |
runElem.addEventListener('click', async () => { | |
const runRequest = { | |
image: 'glot/python:latest', | |
payload: { | |
language: 'python', | |
files: [ | |
{ | |
name: 'main.py', | |
content: codeElem.value, | |
} | |
] | |
} | |
}; | |
const runResult = await runCode(runRequest); | |
resultElem.value = runResult.stdout | |
}); | |
async function runCode(data) { | |
const result = await fetch('/run', { | |
method: 'POST', | |
headers: { | |
"Content-Type": "application/json", | |
"X-Access-Token": "access-token-from-systemd", | |
}, | |
body: JSON.stringify(data) | |
}); | |
return result.json(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment