mirror of
https://github.com/minoplhy/chhoto-url.git
synced 2024-11-22 09:16:46 +00:00
Use env variable for opening database
This commit is contained in:
parent
71d7253248
commit
a14dbf5cd2
@ -22,10 +22,8 @@ struct AppState {
|
|||||||
async fn add_link(req: String, data: web::Data<AppState>) -> HttpResponse {
|
async fn add_link(req: String, data: web::Data<AppState>) -> HttpResponse {
|
||||||
let out = utils::add_link(req, &data.db);
|
let out = utils::add_link(req, &data.db);
|
||||||
if out.0 {
|
if out.0 {
|
||||||
println!("ok{}", out.1);
|
|
||||||
HttpResponse::Ok().body(out.1)
|
HttpResponse::Ok().body(out.1)
|
||||||
} else {
|
} else {
|
||||||
println!("bad{}", out.1);
|
|
||||||
HttpResponse::BadRequest().body(out.1)
|
HttpResponse::BadRequest().body(out.1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,7 +72,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
.app_data(web::Data::new(AppState {
|
.app_data(web::Data::new(AppState {
|
||||||
db: database::open_db("./urls.sqlite".to_string()),
|
db: database::open_db(env::var("db_url").unwrap_or("./urls.sqlite".to_string())),
|
||||||
}))
|
}))
|
||||||
.service(link_handler)
|
.service(link_handler)
|
||||||
.service(error404)
|
.service(error404)
|
||||||
|
Loading…
Reference in New Issue
Block a user