Add binary options

This commit is contained in:
Adrian Woźniak 2022-07-22 15:36:08 +02:00
parent b1b8029e87
commit ee91354de8
No known key found for this signature in database
GPG Key ID: 0012845A89C7352B
4 changed files with 31 additions and 3 deletions

1
Cargo.lock generated
View File

@ -1351,6 +1351,7 @@ dependencies = [
"base64",
"byteorder",
"chrono",
"dotenv",
"futures",
"futures-util",
"gumdrop",

View File

@ -17,6 +17,7 @@ argon2 = { version = "0.4.1" }
askama = { version = "*", features = ["serde-json"] }
byteorder = { version = "1.4.3" }
chrono = { version = "*", features = ["serde"] }
dotenv = { version = "0.15.0" }
futures = { version = "0.3.21", features = ["async-await", "std"] }
futures-util = { version = "0.3.21", features = [] }
gumdrop = { version = "*" }

View File

@ -48,7 +48,6 @@
</svg>
<div>Moje usługi</div>
</ow-path>
{%- endif %}
<ow-path path="/account/offers" selected="{{ page.select_account_offers() }}" title="Moje sprzedaże">
<svg viewBox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
@ -60,6 +59,7 @@
/>
</svg>
</ow-path>
{%- endif %}
{% if h.is_admin(account) -%}
<ow-path path="/admin" selected="{{ page.select_admin_news() }}" title="Admin">

View File

@ -14,14 +14,40 @@ mod routes;
mod utils;
pub mod view;
#[derive(gumdrop::Options)]
struct Opts {
help: bool,
port: Option<String>,
bind: Option<String>,
db: Option<String>,
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let opts: Opts = gumdrop::Options::parse_args_default_or_exit();
dotenv::dotenv().ok();
tracing_subscriber::fmt::init();
let db_addr = std::env::var("DATABASE_URL")
.ok()
.or(opts.db)
.expect("No database connection url");
let addr = (
std::env::var("BIND")
.ok()
.or(opts.bind)
.unwrap_or_else(|| String::from("0.0.0.0")),
std::env::var("PORT")
.ok()
.and_then(|s| s.parse().ok())
.or_else(|| opts.port.and_then(|s| s.parse().ok()))
.unwrap_or(8080),
);
let pool = sqlx::postgres::PgPoolOptions::new()
.max_connections(8)
.min_connections(8)
.connect(&std::env::var("DATABASE_URL").expect("No database connection url"))
.connect(&db_addr)
.await
.unwrap();
@ -41,7 +67,7 @@ async fn main() -> std::io::Result<()> {
.configure(routes::configure)
.default_service(web::to(render_index))
})
.bind(("0.0.0.0", 8080))?
.bind(addr)?
.run()
.await
}