allow binding server to hostname (#1318)
This commit is contained in:
parent
2f9df9350d
commit
d202afeaf5
2 changed files with 6 additions and 12 deletions
|
@ -1,9 +1,6 @@
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
|
|
||||||
use std::{
|
use std::{future::Future, net::TcpListener};
|
||||||
future::Future,
|
|
||||||
net::{IpAddr, SocketAddr, TcpListener},
|
|
||||||
};
|
|
||||||
|
|
||||||
use atuin_server_database::Database;
|
use atuin_server_database::Database;
|
||||||
use axum::Server;
|
use axum::Server;
|
||||||
|
@ -43,13 +40,12 @@ async fn shutdown_signal() {
|
||||||
|
|
||||||
pub async fn launch<Db: Database>(
|
pub async fn launch<Db: Database>(
|
||||||
settings: Settings<Db::Settings>,
|
settings: Settings<Db::Settings>,
|
||||||
host: String,
|
host: &str,
|
||||||
port: u16,
|
port: u16,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let host = host.parse::<IpAddr>()?;
|
|
||||||
launch_with_listener::<Db>(
|
launch_with_listener::<Db>(
|
||||||
settings,
|
settings,
|
||||||
TcpListener::bind(SocketAddr::new(host, port)).context("could not connect to socket")?,
|
TcpListener::bind((host, port)).context("could not connect to socket")?,
|
||||||
shutdown_signal(),
|
shutdown_signal(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -37,12 +37,10 @@ impl Cmd {
|
||||||
match self {
|
match self {
|
||||||
Self::Start { host, port } => {
|
Self::Start { host, port } => {
|
||||||
let settings = Settings::new().wrap_err("could not load server settings")?;
|
let settings = Settings::new().wrap_err("could not load server settings")?;
|
||||||
let host = host
|
let host = host.as_ref().unwrap_or(&settings.host).clone();
|
||||||
.as_ref()
|
let port = port.unwrap_or(settings.port);
|
||||||
.map_or(settings.host.clone(), std::string::ToString::to_string);
|
|
||||||
let port = port.map_or(settings.port, |p| p);
|
|
||||||
|
|
||||||
launch::<Postgres>(settings, host, port).await
|
launch::<Postgres>(settings, &host, port).await
|
||||||
}
|
}
|
||||||
Self::DefaultConfig => {
|
Self::DefaultConfig => {
|
||||||
println!("{}", example_config());
|
println!("{}", example_config());
|
||||||
|
|
Loading…
Reference in a new issue