mirror of
https://github.com/minoplhy/chhoto-url.git
synced 2024-11-22 09:16:46 +00:00
fix: Do not allow empty values for db_url or site_url
This commit is contained in:
parent
b1632c4c87
commit
00ade1af40
@ -60,7 +60,10 @@ async fn getall(data: web::Data<AppState>, session: Session) -> HttpResponse {
|
|||||||
// Get the site URL
|
// Get the site URL
|
||||||
#[get("/api/siteurl")]
|
#[get("/api/siteurl")]
|
||||||
async fn siteurl() -> HttpResponse {
|
async fn siteurl() -> HttpResponse {
|
||||||
let site_url = env::var("site_url").unwrap_or(String::from("unset"));
|
let site_url = env::var("site_url")
|
||||||
|
.ok()
|
||||||
|
.filter(|s| !s.trim().is_empty())
|
||||||
|
.unwrap_or(String::from("unset"));
|
||||||
HttpResponse::Ok().body(site_url)
|
HttpResponse::Ok().body(site_url)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +154,11 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
// Generate session key in runtime so that restart invalidates older logins
|
// Generate session key in runtime so that restart invalidates older logins
|
||||||
let secret_key = Key::generate();
|
let secret_key = Key::generate();
|
||||||
let db_location = env::var("db_url").unwrap_or(String::from("/urls.sqlite"));
|
let db_location = env::var("db_url")
|
||||||
|
.ok()
|
||||||
|
.filter(|s| !s.trim().is_empty())
|
||||||
|
.unwrap_or(String::from("unset"));
|
||||||
|
|
||||||
let port = env::var("port")
|
let port = env::var("port")
|
||||||
.unwrap_or(String::from("4567"))
|
.unwrap_or(String::from("4567"))
|
||||||
.parse::<u16>()
|
.parse::<u16>()
|
||||||
@ -170,7 +177,7 @@ async fn main() -> Result<()> {
|
|||||||
)
|
)
|
||||||
// Maintain a single instance of database throughout
|
// Maintain a single instance of database throughout
|
||||||
.app_data(web::Data::new(AppState {
|
.app_data(web::Data::new(AppState {
|
||||||
db: database::open_db(env::var("db_url").unwrap_or(db_location.clone())),
|
db: database::open_db(db_location.clone()),
|
||||||
}))
|
}))
|
||||||
.service(link_handler)
|
.service(link_handler)
|
||||||
.service(getall)
|
.service(getall)
|
||||||
|
Loading…
Reference in New Issue
Block a user