feat(server): allow configuring the content type for landing page (#48)
* Allow user configuration of content type * style(format): apply formatting --------- Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
This commit is contained in:
parent
8e22d4b71a
commit
9d153ad907
|
@ -31,6 +31,7 @@ changed this.
|
||||||
Check out the GitHub repository at https://github.com/orhun/rustypaste
|
Check out the GitHub repository at https://github.com/orhun/rustypaste
|
||||||
Command line tool is available at https://github.com/orhun/rustypaste-cli
|
Command line tool is available at https://github.com/orhun/rustypaste-cli
|
||||||
"""
|
"""
|
||||||
|
landing_page_content_type = "text/plain; charset=utf-8"
|
||||||
|
|
||||||
[paste]
|
[paste]
|
||||||
random_url = { enabled = true, type = "petname", words = 2, separator = "-" }
|
random_url = { enabled = true, type = "petname", words = 2, separator = "-" }
|
||||||
|
|
|
@ -3,6 +3,7 @@ address="127.0.0.1:8000"
|
||||||
max_content_length="10MB"
|
max_content_length="10MB"
|
||||||
upload_path="./upload"
|
upload_path="./upload"
|
||||||
landing_page="awesome_landing"
|
landing_page="awesome_landing"
|
||||||
|
landing_page_content_type = "text/plain; charset=utf-8"
|
||||||
|
|
||||||
[paste]
|
[paste]
|
||||||
random_url = { enabled = false, type = "petname", words = 2, separator = "-" }
|
random_url = { enabled = false, type = "petname", words = 2, separator = "-" }
|
||||||
|
|
|
@ -29,6 +29,7 @@ If you liked this, consider supporting me: https://donate.orhun.dev <3
|
||||||
|
|
||||||
🦀
|
🦀
|
||||||
"""
|
"""
|
||||||
|
landing_page_content_type = "text/plain; charset=utf-8"
|
||||||
|
|
||||||
[paste]
|
[paste]
|
||||||
# random_url = { enabled = true, type = "petname", words = 2, separator = "-" }
|
# random_url = { enabled = true, type = "petname", words = 2, separator = "-" }
|
||||||
|
|
|
@ -45,6 +45,8 @@ pub struct ServerConfig {
|
||||||
pub auth_token: Option<String>,
|
pub auth_token: Option<String>,
|
||||||
/// Landing page text.
|
/// Landing page text.
|
||||||
pub landing_page: Option<String>,
|
pub landing_page: Option<String>,
|
||||||
|
/// Landing page content-type
|
||||||
|
pub landing_page_content_type: Option<String>,
|
||||||
/// Expose version.
|
/// Expose version.
|
||||||
pub expose_version: Option<bool>,
|
pub expose_version: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,14 @@ async fn index(config: web::Data<RwLock<Config>>) -> Result<HttpResponse, Error>
|
||||||
let config = config
|
let config = config
|
||||||
.read()
|
.read()
|
||||||
.map_err(|_| error::ErrorInternalServerError("cannot acquire config"))?;
|
.map_err(|_| error::ErrorInternalServerError("cannot acquire config"))?;
|
||||||
|
let content_type = config
|
||||||
|
.server
|
||||||
|
.landing_page_content_type
|
||||||
|
.clone()
|
||||||
|
.unwrap_or("text/plain; charset=utf-8".to_string());
|
||||||
match &config.server.landing_page {
|
match &config.server.landing_page {
|
||||||
Some(page) => Ok(HttpResponse::Ok()
|
Some(page) => Ok(HttpResponse::Ok()
|
||||||
.content_type("text/plain; charset=\"UTF-8\"")
|
.content_type(content_type)
|
||||||
.body(page.clone())),
|
.body(page.clone())),
|
||||||
None => Ok(HttpResponse::Found()
|
None => Ok(HttpResponse::Found()
|
||||||
.append_header(("Location", env!("CARGO_PKG_HOMEPAGE")))
|
.append_header(("Location", env!("CARGO_PKG_HOMEPAGE")))
|
||||||
|
|
Loading…
Reference in New Issue