feat: redirect to url if article has its specific url setting.
This commit is contained in:
parent
6b148d608d
commit
b9ba4f23b0
@ -24,3 +24,4 @@ actix-files = "0.1.0-alpha.6"
|
|||||||
actix = "0.8.1"
|
actix = "0.8.1"
|
||||||
diesel_migrations = "1.4.0"
|
diesel_migrations = "1.4.0"
|
||||||
futures = "0.1.26"
|
futures = "0.1.26"
|
||||||
|
http = "0.1.17"
|
||||||
|
@ -43,6 +43,10 @@ pub fn single_article(
|
|||||||
}
|
}
|
||||||
let article1 = article.unwrap();
|
let article1 = article.unwrap();
|
||||||
|
|
||||||
|
if let Some(to) = article1.url {
|
||||||
|
return RubbleResponder::Redirect(format!("/{}", to));
|
||||||
|
}
|
||||||
|
|
||||||
let view = ArticleView::from(&article1);
|
let view = ArticleView::from(&article1);
|
||||||
|
|
||||||
let settings = Setting::load(&connection);
|
let settings = Setting::load(&connection);
|
||||||
|
@ -3,6 +3,7 @@ use actix_web::{HttpRequest, HttpResponse, Responder};
|
|||||||
pub mod article;
|
pub mod article;
|
||||||
use actix_web::error::Error;
|
use actix_web::error::Error;
|
||||||
use futures::future::{err, ok, FutureResult};
|
use futures::future::{err, ok, FutureResult};
|
||||||
|
|
||||||
//pub mod admin;
|
//pub mod admin;
|
||||||
//pub mod rss;
|
//pub mod rss;
|
||||||
//pub mod catacher;
|
//pub mod catacher;
|
||||||
@ -12,6 +13,7 @@ pub enum RubbleResponder {
|
|||||||
Html(String),
|
Html(String),
|
||||||
Redirect(String),
|
Redirect(String),
|
||||||
NotFound,
|
NotFound,
|
||||||
|
RedirectPermanently(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Responder for RubbleResponder {
|
impl Responder for RubbleResponder {
|
||||||
@ -23,10 +25,13 @@ impl Responder for RubbleResponder {
|
|||||||
RubbleResponder::Html(content) => ok(HttpResponse::Ok()
|
RubbleResponder::Html(content) => ok(HttpResponse::Ok()
|
||||||
.content_type("text/html; charset=utf-8")
|
.content_type("text/html; charset=utf-8")
|
||||||
.body(content)),
|
.body(content)),
|
||||||
RubbleResponder::Redirect(content) => ok(HttpResponse::Ok()
|
RubbleResponder::Redirect(to) => ok(HttpResponse::Found()
|
||||||
.content_type("text/html")
|
.header(http::header::LOCATION, to)
|
||||||
.body("redirect")),
|
.finish()),
|
||||||
RubbleResponder::NotFound => ok(HttpResponse::NotFound().finish()),
|
RubbleResponder::NotFound => ok(HttpResponse::NotFound().finish()),
|
||||||
|
RubbleResponder::RedirectPermanently(to) => ok(HttpResponse::MovedPermanently()
|
||||||
|
.header(http::header::LOCATION, to)
|
||||||
|
.finish()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user