initial test project
This commit is contained in:
parent
e8f9f722a3
commit
f46a9b690c
|
@ -14,3 +14,8 @@ Cargo.lock
|
||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "url_shortener"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
axum = { version = "0.6.20", features = ["http2"] }
|
||||||
|
ini = "1.3.0"
|
||||||
|
redis = { version = "0.23.3", features = ["r2d2", "ahash", "connection-manager"] }
|
||||||
|
tokio = { version = "1.34.0", features = ["full"] }
|
|
@ -0,0 +1,6 @@
|
||||||
|
[database]
|
||||||
|
type = redis
|
||||||
|
server = 127.0.0.1:6379
|
||||||
|
|
||||||
|
[web_server]
|
||||||
|
bind_address = 127.0.0.1:12432
|
|
@ -0,0 +1,54 @@
|
||||||
|
mod url_shortener;
|
||||||
|
mod database_adapter;
|
||||||
|
mod redis_adapter;
|
||||||
|
|
||||||
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
|
use ini::ini;
|
||||||
|
use axum::{routing::get, Router, response::Html};
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let config = ini!("config.ini");
|
||||||
|
let server_address = match &config["database"]["server"] {
|
||||||
|
Some(adr) => adr,
|
||||||
|
None => panic!("Could not find [database]/server in config")
|
||||||
|
};
|
||||||
|
let web_bind_address = match &config["web_server"]["bind_address"] {
|
||||||
|
Some(adr) => adr,
|
||||||
|
None => panic!("Could not find [web_server]/bind_address in config")
|
||||||
|
};
|
||||||
|
|
||||||
|
let app = Router::new()
|
||||||
|
.route("/", get(root))
|
||||||
|
.route("/test", get(get_test).post(post_test));
|
||||||
|
|
||||||
|
let addr: SocketAddr = web_bind_address.parse().expect("Unable to parse [web_server]/bind_address in config");
|
||||||
|
|
||||||
|
dbg!(addr);
|
||||||
|
|
||||||
|
axum::Server::bind(&addr)
|
||||||
|
.serve(app.into_make_service())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn root() -> Html<&'static str> {
|
||||||
|
Html("root<br>
|
||||||
|
<a href=\"/test\">test</a>
|
||||||
|
<br>
|
||||||
|
<form action=\"test\" method=\"post\">
|
||||||
|
<input type=\"submit\" />
|
||||||
|
</form>
|
||||||
|
")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_test() -> &'static str {
|
||||||
|
"get_test"
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn post_test() -> &'static str {
|
||||||
|
"post_test"
|
||||||
|
}
|
Loading…
Reference in New Issue