Skip to content

Commit

Permalink
Merge pull request 'feat: use medium.com's URL patterns' (#9) from fix-
Browse files Browse the repository at this point in the history
  • Loading branch information
realaravinth committed Dec 7, 2023
2 parents a1491cb + 2272eaa commit a92f7e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub mod routes {
pub by_post_id: &'static str,
pub page: &'static str,
pub asset: &'static str,
pub top_level_post: &'static str,
}

impl Proxy {
Expand All @@ -43,6 +44,7 @@ pub mod routes {
by_post_id: "/utils/post/{post}",
page: "/{username}/{post}",
asset: "/asset/medium/{name}",
top_level_post: "/{post}",
}
}
pub fn get_page(&self, username: &str, post: &str) -> String {
Expand Down Expand Up @@ -167,6 +169,23 @@ async fn by_post_id(path: web::Path<String>, data: AppData) -> impl Responder {
.finish()
}

#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.top_level_post")]
async fn by_top_level_post(path: web::Path<String>, data: AppData) -> impl Responder {
if let Some(post_id) = path.split('-').last() {
let post_data = data.get_post_light(post_id).await;
HttpResponse::Found()
.append_header((
header::LOCATION,
crate::V1_API_ROUTES
.proxy
.get_page(&post_data.username, &post_data.slug),
))
.finish()
} else {
HttpResponse::NotFound().body("Post not found, please file bug report")
}
}

#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.page")]
async fn page(path: web::Path<(String, String)>, data: AppData) -> impl Responder {
let post_id = path.1.split('-').last();
Expand Down Expand Up @@ -238,6 +257,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
cfg.service(by_post_id);
cfg.service(assets);
cfg.service(page);
cfg.service(by_top_level_post);
cfg.service(index);
}

Expand Down
1 change: 0 additions & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ impl Settings {

s = s.add_source(Environment::with_prefix("PAGES").separator("__"));


match env::var("PORT") {
Ok(val) => {
s = s.set_override("server.port", val).unwrap();
Expand Down

0 comments on commit a92f7e3

Please sign in to comment.