API draft, lang config, more utils

This commit is contained in:
Radon Rosborough 2020-06-05 22:21:55 -06:00
parent 4b82e93042
commit c7a62924e6
6 changed files with 103 additions and 0 deletions

58
README.md Normal file
View File

@ -0,0 +1,58 @@
# Fast Sandbox
This project is a work in progress and does not contain any serious
documentation.
## API
POST /api/v1/ws?lang=python
The API is based on message passing.
### Server messages
Received output from process.
{
"event": "terminalOutput",
"output": ">>> "
}
Package name completions.
{
"event": "packageNameCompletions",
"packageNameCompletions": ["Flask", "Flask-Talisman"],
"messageSerial": 42
}
### Client messages
Received input from user.
{
"event": "terminalInput",
"input": "print('Hello, world!')\n"
}
User wants to run code.
{
"event": "runCode",
"code": "import this"
}
User wants to install a package.
{
"event": "installPackage",
"packageName": "Flask"
}
Complete package names.
{
"event": "completePackageName",
"partialPackageName": "fla",
"messageSerial": 42
}

10
dynamic/app.html Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Fast Sandbox</title>
</head>
<body>
Editor :)
</body>
</html>

17
langs.json Normal file
View File

@ -0,0 +1,17 @@
{
"c": {
"name": "C"
},
"c++": {
"name": "C++"
},
"haskell": {
"name": "Haskell"
},
"nodejs": {
"name": "Node.js"
},
"python": {
"name": "Python"
}
}

View File

@ -19,6 +19,7 @@ emacs-nox
git
make
nano
sudo
vim
wget
@ -45,6 +46,11 @@ apt-get update
apt-get install -y $(grep -v "^#" <<< "$packages")
rm -rf /var/lib/apt/lists/*
cd /tmp
wget -nv https://github.com/watchexec/watchexec/releases/download/1.13.1/watchexec-1.13.1-x86_64-unknown-linux-gnu.deb
dpkg -i watchexec-*.deb
rm watchexec-*.deb
if (( "$uid" != 0 )); then
useradd --uid="$uid" --create-home --groups sudo docker
passwd -d docker

View File

@ -7,6 +7,8 @@ export LANG=C.UTF-8
export LC_ALL=C.UTF-8
export SHELL="$(which bash)"
export HOST=0.0.0.0
if [[ -d src ]]; then
cd src
fi

View File

@ -1,4 +1,7 @@
const appRoot = require("app-root-path");
const langs = require(appRoot + "/langs");
const express = require("express");
const sslRedirect = require("heroku-ssl-redirect");
@ -7,6 +10,13 @@ const host = process.env.HOST || "localhost";
const port = parseInt(process.env.PORT) || 6119;
app.use(sslRedirect());
app.get("/:lang", (req, res) => {
if (langs[req.params.lang]) {
res.sendFile(appRoot + "/dynamic/app.html");
} else {
res.send(`No such language: ${req.params.lang}`);
}
});
app.use("/", express.static(appRoot + "/static"));
app.listen(port, host, () =>