53 lines
1.2 KiB
Rust
53 lines
1.2 KiB
Rust
|
use rocket::{fs::FileServer, get, routes, State};
|
||
|
use s3::S3;
|
||
|
use tracing::{info, Level};
|
||
|
use url::Url;
|
||
|
|
||
|
mod s3;
|
||
|
|
||
|
struct Config<'a> {
|
||
|
s3_url: &'a str,
|
||
|
s3_bucket: &'a str,
|
||
|
s3_access_key: &'a str,
|
||
|
s3_secret_key: &'a str,
|
||
|
}
|
||
|
|
||
|
#[rocket::main]
|
||
|
async fn main() {
|
||
|
tracing_subscriber::fmt()
|
||
|
.with_line_number(false)
|
||
|
.without_time()
|
||
|
.with_max_level(Level::INFO)
|
||
|
.init();
|
||
|
|
||
|
let config = Config {
|
||
|
s3_bucket: "v1.10",
|
||
|
s3_url: "http://localhost:9000",
|
||
|
s3_access_key: "8UO76z8wCs9DnpxSbQUY",
|
||
|
s3_secret_key: "xwKVMpf2jzgprsdo85Dvo74UmO84y0aRrAUorYY5",
|
||
|
};
|
||
|
|
||
|
let s3 = S3::connect(&config).await.expect("Failed to connect to minio, aborting.");
|
||
|
|
||
|
let _ = rocket::build()
|
||
|
.mount("/", FileServer::new("www/"))
|
||
|
.mount("/", routes![get_s3_content])
|
||
|
.manage(s3)
|
||
|
.launch()
|
||
|
.await;
|
||
|
|
||
|
info!("Bye");
|
||
|
}
|
||
|
|
||
|
#[get("/<path>")]
|
||
|
async fn get_s3_content(path: &str, db: &State<S3>) -> String {
|
||
|
info!(path);
|
||
|
// TODO this is just pseudo-code
|
||
|
let url = "en.wikipedia.org/wiki/CNBC";
|
||
|
if let Some(resp) = db.get(&url).await {
|
||
|
return resp
|
||
|
}
|
||
|
"Hello world.".to_owned()
|
||
|
}
|
||
|
|