base rocket boilerplate for client web app
This commit is contained in:
parent
ceaf591c9f
commit
b07234f114
4
client/src/Rocket.toml
Normal file
4
client/src/Rocket.toml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[development]
|
||||||
|
address="localhost"
|
||||||
|
port=8080
|
||||||
|
|
55
client/src/main.rs
Normal file
55
client/src/main.rs
Normal 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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user