add placeholder main page
This commit is contained in:
parent
633778d732
commit
6840415069
18
src/main.rs
18
src/main.rs
@ -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
10
static/page.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>url shortener</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
(url shortener)
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user