base rocket boilerplate for client web app

This commit is contained in:
shockrah 2019-11-10 16:31:11 -08:00
parent ceaf591c9f
commit b07234f114
2 changed files with 59 additions and 0 deletions

4
client/src/Rocket.toml Normal file
View File

@ -0,0 +1,4 @@
[development]
address="localhost"
port=8080

55
client/src/main.rs Normal file
View File

@ -0,0 +1,55 @@
// Client based web server app
// Built to serve the purpose of being a basic web client's backend
// For now this the backend for the web client
#![feature(proc_macro_hygiene, decl_macro, plugin)]
//#[macro_use] extern crate serde_derive;
#[macro_use] extern crate rocket;
extern crate rocket_contrib;
use rocket::response::NamedFile;
use std::io;
macro_rules! page {
($type:expr, $item:expr) => {
// TODO: verify against directory traversals
NamedFile::open(format!("staic/{}/{}", $type, $item))
}
}
// Pages themselves
#[get("/")]
fn homepage() -> io::Result<NamedFile> {
// Be sure to include some kind of prompt
page!("html", "index")
}
// Handles logging in a user to their home instance
#[get("/login")]
fn login_page() -> io::Result<NamedFile> {
page!("html", "login")
}
#[get("/servers")]
fn server_info() -> io::Result<NamedFile> {
page!("html", "servers")
}
// Genearl resources
#[get("/static/css/<stylesheet>")]
fn static_css(stylesheet: String) -> io::Result<NamedFile> {
page!("css", stylesheet)
}
#[get("/static/js/<javascript>")]
fn static_js(javascript: String) -> io::Result<NamedFile> {
page!("js", javascript)
}
fn main() {
rocket::ignite()
.mount("/", routes![
homepage, login_page, server_info
])
.mount("/static", routes![
static_css, static_js
])
.launch();
}