Allow specifying IP address to listen on
This commit is contained in:
parent
0e2d440489
commit
fa7dc5a3f9
4 changed files with 16 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
|||
padlock-secret = ""
|
||||
port = 80
|
||||
listen = "[::]:80"
|
||||
|
||||
[database]
|
||||
connection-string = "sqlite://sqlite.db"
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
use std::net::{Ipv6Addr, SocketAddr, SocketAddrV6};
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::secrets::PadlockGenerationSecret;
|
||||
|
||||
fn default_listen_addr() -> SocketAddr {
|
||||
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, 80, 0, 0))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct Config {
|
||||
#[serde(with = "hex::serde")]
|
||||
pub padlock_secret: PadlockGenerationSecret,
|
||||
pub port: u16,
|
||||
#[serde(default = "default_listen_addr")]
|
||||
pub listen: SocketAddr,
|
||||
|
||||
pub database: DatabaseConfig,
|
||||
#[serde(default)]
|
||||
|
|
|
@ -99,7 +99,7 @@ async fn main() -> Result<()> {
|
|||
));
|
||||
|
||||
tokio::spawn(server::run(
|
||||
config.port,
|
||||
config.listen,
|
||||
user_authenticator,
|
||||
padlock_generator,
|
||||
user_server_key_generator,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{net::Ipv6Addr, sync::Arc};
|
||||
use std::{net::SocketAddr, sync::Arc};
|
||||
|
||||
use axum::{
|
||||
extract::{Query, State},
|
||||
|
@ -7,6 +7,7 @@ use axum::{
|
|||
routing::{get, post},
|
||||
Form, Json, Router,
|
||||
};
|
||||
use color_eyre::eyre::Context;
|
||||
use secrecy::ExposeSecret;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::{event, instrument, Level};
|
||||
|
@ -25,7 +26,7 @@ struct AppState {
|
|||
|
||||
#[instrument]
|
||||
pub async fn run(
|
||||
port: u16,
|
||||
listen: SocketAddr,
|
||||
user_authenticator: Arc<UserAuthenticator>,
|
||||
server_padlock_generator: Arc<ServerPadlockGenerator>,
|
||||
user_server_key_generator: Arc<UserServerKeyGenerator>,
|
||||
|
@ -49,7 +50,9 @@ pub async fn run(
|
|||
)
|
||||
.with_state(app_state);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind((Ipv6Addr::UNSPECIFIED, port)).await?;
|
||||
let listener = tokio::net::TcpListener::bind(listen)
|
||||
.await
|
||||
.context(format!("Failed to listen on {listen}"))?;
|
||||
axum::serve(listener, app).await?;
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue