schala/src/webapp.rs

36 lines
801 B
Rust
Raw Normal View History

use rocket;
use rocket::response::NamedFile;
2017-09-19 20:29:08 -07:00
use rocket_contrib::Json;
#[get("/")]
fn index() -> Result<NamedFile, ()> {
NamedFile::open("static/index.html").map_err(|_| ())
}
#[get("/bundle.js")]
fn js_bundle() -> Result<NamedFile, ()> {
NamedFile::open("static/bundle.js").map_err(|_| ())
}
2017-10-01 23:25:36 -07:00
#[derive(Debug, Serialize, Deserialize)]
2017-09-19 20:29:08 -07:00
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> {
2017-10-01 23:25:36 -07:00
println!("INPUT {:?}", input);
2017-09-19 20:29:08 -07:00
let output = Output { text: "test interpreter output".to_string() };
Json(output)
}
pub fn web_main() {
rocket::ignite().mount("/", routes![index, js_bundle, interpreter_input]).launch();
}