A tiny bit more work on the webapp

This commit is contained in:
greg 2017-09-19 20:29:08 -07:00
parent 88209d370d
commit 7ac5846282
5 changed files with 29 additions and 3 deletions

View File

@ -18,4 +18,5 @@ serde_derive = "1.0.15"
serde_json = "1.0.3"
rocket = "*"
rocket_codegen = "*"
rocket_contrib = "*"

View File

@ -12,6 +12,7 @@ extern crate maplit;
extern crate serde_derive;
extern crate serde_json;
extern crate rocket;
extern crate rocket_contrib;
use std::path::Path;
use std::fs::File;

View File

@ -1,12 +1,29 @@
use rocket;
use rocket::response::NamedFile;
use rocket_contrib::Json;
#[get("/")]
fn index() -> Result<NamedFile, ()> {
NamedFile::open("static/index.html").map_err(|_| ())
}
pub fn web_main() {
rocket::ignite().mount("/", routes![index]).launch();
#[derive(Serialize, Deserialize)]
struct Input {
source: String,
}
#[derive(Serialize, Deserialize)]
struct Output {
text: String,
}
#[post("/input", format = "application/json", data = "<input>")]
fn interpreter_input(input: Json<Input>) -> Json<Output> {
let output = Output { text: "test interpreter output".to_string() };
Json(output)
}
pub fn web_main() {
rocket::ignite().mount("/", routes![index, interpreter_input]).launch();
}

View File

@ -3,6 +3,10 @@
<head>
</head>
<body>
Test
Type your source code into here:
<textarea class="code-input">
</textarea>
<script src="main.js"></script>
</body>
</html>

3
static/main.js Normal file
View File

@ -0,0 +1,3 @@
console.log("YOLO");