Created
August 2, 2019 15:21
-
-
Save imclint21/f13c6d49332821ead83a6a7f007468ca to your computer and use it in GitHub Desktop.
Making an SPA Application In Rust with Rocket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(plugin)] | |
#![plugin(rocket_codegen)] | |
extern crate rocket; | |
use std::io; | |
use std::path::{Path, PathBuf}; | |
use rocket::response::NamedFile; | |
#[get("/")] | |
fn index() -> io::Result<NamedFile> { | |
NamedFile::open("dist/index.html") | |
} | |
#[get("/<file..>")] | |
fn files(file: PathBuf) -> Option<NamedFile> { | |
NamedFile::open(Path::new("dist/").join(file)).ok() | |
} | |
fn main() { | |
rocket::ignite().mount("/", routes![index, files]).launch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment