Convert webapp to using included files

This commit is contained in:
greg 2017-10-12 02:13:55 -07:00
parent cd5fc36c37
commit db835f42aa
4 changed files with 30 additions and 5 deletions

View File

@ -19,4 +19,8 @@ serde_json = "1.0.3"
rocket = "*"
rocket_codegen = "*"
rocket_contrib = "*"
phf = "0.7.12"
includedir = "0.2.0"
[build-dependencies]
includedir_codegen = "0.2.0"

10
build.rs Normal file
View File

@ -0,0 +1,10 @@
extern crate includedir_codegen;
use includedir_codegen::Compression;
fn main() {
includedir_codegen::start("WEBFILES")
.dir("static", Compression::Gzip)
.build("static.rs")
.unwrap();
}

View File

@ -13,6 +13,8 @@ extern crate serde_derive;
extern crate serde_json;
extern crate rocket;
extern crate rocket_contrib;
extern crate includedir;
extern crate phf;
use std::path::Path;
use std::fs::File;
@ -30,6 +32,8 @@ use language::{ProgrammingLanguageInterface, EvalOptions, LLVMCodeString};
mod webapp;
mod llvm_wrap;
include!(concat!(env!("OUT_DIR"), "/static.rs"));
fn main() {
let languages: Vec<Box<ProgrammingLanguageInterface>> =
vec![

View File

@ -1,17 +1,24 @@
use rocket;
use rocket::response::NamedFile;
use rocket::response::Content;
use rocket::http::ContentType;
use rocket_contrib::Json;
use schala_lang;
use language::{ProgrammingLanguageInterface, EvalOptions};
use WEBFILES;
#[get("/")]
fn index() -> Result<NamedFile, ()> {
NamedFile::open("static/index.html").map_err(|_| ())
fn index() -> Content<String> {
let path = "static/index.html";
let html_contents = String::from_utf8(WEBFILES.get(path).unwrap().into_owned()).unwrap();
Content(ContentType::HTML, html_contents)
}
#[get("/bundle.js")]
fn js_bundle() -> Result<NamedFile, ()> {
NamedFile::open("static/bundle.js").map_err(|_| ())
fn js_bundle() -> Content<String> {
let path = "static/bundle.js";
let js_contents = String::from_utf8(WEBFILES.get(path).unwrap().into_owned()).unwrap();
Content(ContentType::JavaScript, js_contents)
}
#[derive(Debug, Serialize, Deserialize)]