mirror of
https://github.com/SinTan1729/chhoto-url
synced 2024-12-26 07:38:36 -06:00
Use env variable for opening database
This commit is contained in:
parent
71d7253248
commit
a14dbf5cd2
1 changed files with 1 additions and 3 deletions
|
@ -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 a new issue