2017-09-19 03:32:15 -07:00
|
|
|
use rocket;
|
|
|
|
|
|
|
|
use rocket::response::NamedFile;
|
2017-09-19 20:29:08 -07:00
|
|
|
use rocket_contrib::Json;
|
2017-09-19 03:32:15 -07:00
|
|
|
|
2017-09-19 01:54:54 -07:00
|
|
|
#[get("/")]
|
2017-09-19 03:32:15 -07:00
|
|
|
fn index() -> Result<NamedFile, ()> {
|
|
|
|
NamedFile::open("static/index.html").map_err(|_| ())
|
2017-09-19 01:54:54 -07:00
|
|
|
}
|
|
|
|
|
2017-09-20 23:21:45 -07:00
|
|
|
#[get("/bundle.js")]
|
|
|
|
fn js_bundle() -> Result<NamedFile, ()> {
|
|
|
|
NamedFile::open("static/bundle.js").map_err(|_| ())
|
|
|
|
}
|
|
|
|
|
2017-09-19 20:29:08 -07:00
|
|
|
#[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)
|
|
|
|
}
|
|
|
|
|
2017-09-19 03:32:15 -07:00
|
|
|
pub fn web_main() {
|
2017-09-20 23:21:45 -07:00
|
|
|
rocket::ignite().mount("/", routes![index, js_bundle, interpreter_input]).launch();
|
2017-09-19 01:54:54 -07:00
|
|
|
}
|