Skip to content

Instantly share code, notes, and snippets.

@imclint21
Created August 2, 2019 15:21
Show Gist options
  • Save imclint21/f13c6d49332821ead83a6a7f007468ca to your computer and use it in GitHub Desktop.
Save imclint21/f13c6d49332821ead83a6a7f007468ca to your computer and use it in GitHub Desktop.
Making an SPA Application In Rust with Rocket
#![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