add placeholder main page

This commit is contained in:
Slavasil 2024-10-03 19:19:12 +03:00
parent 633778d732
commit 6840415069
2 changed files with 27 additions and 3 deletions

View File

@ -1,5 +1,6 @@
use rocket::{futures::lock::Mutex, get, http::Status, response::Redirect, routes, State}; use rocket::{futures::lock::Mutex, get, http::Status, response::Redirect, response::content::RawHtml, routes, State};
use tokio_postgres::{Client, NoTls, Statement}; use tokio_postgres::{Client, NoTls, Statement};
use std::fs::File;
mod db; mod db;
mod linkgen; mod linkgen;
@ -24,14 +25,27 @@ async fn main() {
}); });
db::prepare_tables(&client).await.unwrap(); db::prepare_tables(&client).await.unwrap();
let statements = db::prepare_statements(&client).await.unwrap(); let statements = db::prepare_statements(&client).await.unwrap();
let mut config = rocket::Config::default();
config.port = 3020;
let state = GlobalState { db_client: client, stmt_get_link: statements.0, stmt_add_link: statements.1 }; let state = GlobalState { db_client: client, stmt_get_link: statements.0, stmt_add_link: statements.1 };
rocket::build() rocket::build()
.mount("/", routes![create, go_to_link]) .mount("/", routes![main_page, create, go_to_link])
.manage(Mutex::new(state)) .manage(Mutex::new(state))
.configure(config)
.launch() .launch()
.await.unwrap(); .await.unwrap();
} }
#[get("/")]
fn main_page() -> Result<RawHtml<File>, Status> {
match File::open("./static/page.html") {
Ok(f) => Ok(RawHtml(f)),
Err(e) => {
eprintln!("open static page error: {}", e);
Err(Status::InternalServerError)
}
}
}
#[get("/create?<url>&<secret>&<length>&<link>")] #[get("/create?<url>&<secret>&<length>&<link>")]
async fn create(state: &State<Mutex<GlobalState>>, url: &str, secret: Option<&str>, length: Option<u32>, link: Option<&str>) -> (Status, String) { async fn create(state: &State<Mutex<GlobalState>>, url: &str, secret: Option<&str>, length: Option<u32>, link: Option<&str>) -> (Status, String) {
let mut allow_secret_options = false; let mut allow_secret_options = false;

10
static/page.html Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>url shortener</title>
</head>
<body>
(url shortener)
</body>
</html>