Convert webapp to using included files
This commit is contained in:
parent
cd5fc36c37
commit
db835f42aa
@ -19,4 +19,8 @@ serde_json = "1.0.3"
|
|||||||
rocket = "*"
|
rocket = "*"
|
||||||
rocket_codegen = "*"
|
rocket_codegen = "*"
|
||||||
rocket_contrib = "*"
|
rocket_contrib = "*"
|
||||||
|
phf = "0.7.12"
|
||||||
|
includedir = "0.2.0"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
includedir_codegen = "0.2.0"
|
||||||
|
10
build.rs
Normal file
10
build.rs
Normal 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();
|
||||||
|
}
|
@ -13,6 +13,8 @@ extern crate serde_derive;
|
|||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
extern crate rocket_contrib;
|
extern crate rocket_contrib;
|
||||||
|
extern crate includedir;
|
||||||
|
extern crate phf;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
@ -30,6 +32,8 @@ use language::{ProgrammingLanguageInterface, EvalOptions, LLVMCodeString};
|
|||||||
mod webapp;
|
mod webapp;
|
||||||
mod llvm_wrap;
|
mod llvm_wrap;
|
||||||
|
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/static.rs"));
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let languages: Vec<Box<ProgrammingLanguageInterface>> =
|
let languages: Vec<Box<ProgrammingLanguageInterface>> =
|
||||||
vec![
|
vec![
|
||||||
|
@ -1,17 +1,24 @@
|
|||||||
use rocket;
|
use rocket;
|
||||||
use rocket::response::NamedFile;
|
use rocket::response::Content;
|
||||||
|
use rocket::http::ContentType;
|
||||||
use rocket_contrib::Json;
|
use rocket_contrib::Json;
|
||||||
use schala_lang;
|
use schala_lang;
|
||||||
use language::{ProgrammingLanguageInterface, EvalOptions};
|
use language::{ProgrammingLanguageInterface, EvalOptions};
|
||||||
|
use WEBFILES;
|
||||||
|
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> Result<NamedFile, ()> {
|
fn index() -> Content<String> {
|
||||||
NamedFile::open("static/index.html").map_err(|_| ())
|
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")]
|
#[get("/bundle.js")]
|
||||||
fn js_bundle() -> Result<NamedFile, ()> {
|
fn js_bundle() -> Content<String> {
|
||||||
NamedFile::open("static/bundle.js").map_err(|_| ())
|
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)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
Loading…
Reference in New Issue
Block a user