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"
|
||||
diesel_migrations = "1.4.0"
|
||||
futures = "0.1.26"
|
||||
http = "0.1.17"
|
||||
|
@ -43,6 +43,10 @@ pub fn single_article(
|
||||
}
|
||||
let article1 = article.unwrap();
|
||||
|
||||
if let Some(to) = article1.url {
|
||||
return RubbleResponder::Redirect(format!("/{}", to));
|
||||
}
|
||||
|
||||
let view = ArticleView::from(&article1);
|
||||
|
||||
let settings = Setting::load(&connection);
|
||||
|
@ -3,6 +3,7 @@ use actix_web::{HttpRequest, HttpResponse, Responder};
|
||||
pub mod article;
|
||||
use actix_web::error::Error;
|
||||
use futures::future::{err, ok, FutureResult};
|
||||
|
||||
//pub mod admin;
|
||||
//pub mod rss;
|
||||
//pub mod catacher;
|
||||
@ -12,6 +13,7 @@ pub enum RubbleResponder {
|
||||
Html(String),
|
||||
Redirect(String),
|
||||
NotFound,
|
||||
RedirectPermanently(String),
|
||||
}
|
||||
|
||||
impl Responder for RubbleResponder {
|
||||
@ -23,10 +25,13 @@ impl Responder for RubbleResponder {
|
||||
RubbleResponder::Html(content) => ok(HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(content)),
|
||||
RubbleResponder::Redirect(content) => ok(HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.body("redirect")),
|
||||
RubbleResponder::Redirect(to) => ok(HttpResponse::Found()
|
||||
.header(http::header::LOCATION, to)
|
||||
.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