Commit 5bd95da6 authored by marisa's avatar marisa

basic site functionality

parent 8f00fd67
use actix_web::{server, App, HttpRequest};
use actix_web::{http::header, http::Method, server, App, HttpRequest, HttpResponse};
fn index(_req: &HttpRequest) -> &'static str {
"Hello world!"
fn normal_crate(req: HttpRequest) -> HttpResponse {
let cratename: String = req.match_info().query("crate").unwrap();
HttpResponse::PermanentRedirect()
.header(header::LOCATION, format!("https://crates.io/crates/{}", cratename))
.finish()
}
fn docs_rs(req: HttpRequest) -> HttpResponse {
let cratename: String = req.match_info().query("crate").unwrap();
HttpResponse::PermanentRedirect()
.header(header::LOCATION, format!("https://docs.rs/{}", cratename))
.finish()
}
fn main() {
server::new(|| App::new().resource("/", |r| r.f(index)))
server::new(|| App::new()
.route("/d/{crate:.*}", Method::GET, docs_rs)
.route("/{crate:.*}", Method::GET, normal_crate))
.bind("127.0.0.1:8080")
.unwrap()
.run();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment