From 7ac5846282b93b46c5f0573b883366bf3bd213d5 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 19 Sep 2017 20:29:08 -0700 Subject: [PATCH] A tiny bit more work on the webapp --- Cargo.toml | 1 + src/main.rs | 1 + src/webapp.rs | 21 +++++++++++++++++++-- static/index.html | 6 +++++- static/main.js | 3 +++ 5 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 static/main.js diff --git a/Cargo.toml b/Cargo.toml index 722f2ab..240648b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,5 @@ serde_derive = "1.0.15" serde_json = "1.0.3" rocket = "*" rocket_codegen = "*" +rocket_contrib = "*" diff --git a/src/main.rs b/src/main.rs index ef1cc2f..fa14365 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; diff --git a/src/webapp.rs b/src/webapp.rs index e585b7c..af53c7e 100644 --- a/src/webapp.rs +++ b/src/webapp.rs @@ -1,12 +1,29 @@ use rocket; use rocket::response::NamedFile; +use rocket_contrib::Json; #[get("/")] fn index() -> Result { 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 = "")] +fn interpreter_input(input: Json) -> Json { + let output = Output { text: "test interpreter output".to_string() }; + Json(output) +} + +pub fn web_main() { + rocket::ignite().mount("/", routes![index, interpreter_input]).launch(); } diff --git a/static/index.html b/static/index.html index 24c40c9..d8a2390 100644 --- a/static/index.html +++ b/static/index.html @@ -3,6 +3,10 @@ - Test + Type your source code into here: + + diff --git a/static/main.js b/static/main.js new file mode 100644 index 0000000..d802934 --- /dev/null +++ b/static/main.js @@ -0,0 +1,3 @@ + + +console.log("YOLO");