parent
6d087bd155
commit
c6ba724434
|
@ -3,6 +3,9 @@
|
||||||
# The port the server should listen on
|
# The port the server should listen on
|
||||||
port: 1312
|
port: 1312
|
||||||
|
|
||||||
|
# The address the server should bind to
|
||||||
|
address: 0.0.0.0
|
||||||
|
|
||||||
# A list of pronouns recognized by the server
|
# A list of pronouns recognized by the server
|
||||||
#
|
#
|
||||||
# WARNING: When adding pronouns, only add pronouns to the bottom of the list, and do not
|
# WARNING: When adding pronouns, only add pronouns to the bottom of the list, and do not
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::net::Ipv4Addr;
|
||||||
|
use std::net::IpAddr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use pronouns_today::PronounList;
|
use pronouns_today::PronounList;
|
||||||
use pronouns_today::UserPreferences;
|
use pronouns_today::UserPreferences;
|
||||||
|
@ -66,6 +68,10 @@ pub struct Run {
|
||||||
/// the port to listen on
|
/// the port to listen on
|
||||||
pub port: Option<u16>,
|
pub port: Option<u16>,
|
||||||
|
|
||||||
|
#[argh(option)]
|
||||||
|
/// the address to bind to
|
||||||
|
pub address: Option<IpAddr>,
|
||||||
|
|
||||||
#[argh(option)]
|
#[argh(option)]
|
||||||
/// default pronoun probabilites (formatted as a prefstring, like the ones in the
|
/// default pronoun probabilites (formatted as a prefstring, like the ones in the
|
||||||
/// used in the custom URLs, e.g. "acaqeawdym")
|
/// used in the custom URLs, e.g. "acaqeawdym")
|
||||||
|
@ -122,11 +128,15 @@ pub struct Conf {
|
||||||
|
|
||||||
/// The port for the server to bind to. Defaults to 1312
|
/// The port for the server to bind to. Defaults to 1312
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
|
|
||||||
|
/// The address to bind to. Defaults to 0.0.0.0
|
||||||
|
pub address: IpAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Conf {
|
impl Conf {
|
||||||
fn update_with(mut self, args: Run) -> Conf {
|
fn update_with(mut self, args: Run) -> Conf {
|
||||||
self.port = args.port.unwrap_or(self.port);
|
self.port = args.port.unwrap_or(self.port);
|
||||||
|
self.address = args.address.unwrap_or(self.address);
|
||||||
self.instance_settings.pronoun_list = args.pronouns.map(Into::into).unwrap_or(self.instance_settings.pronoun_list);
|
self.instance_settings.pronoun_list = args.pronouns.map(Into::into).unwrap_or(self.instance_settings.pronoun_list);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -137,6 +147,7 @@ impl Default for Conf {
|
||||||
Conf {
|
Conf {
|
||||||
instance_settings: InstanceSettings::default(),
|
instance_settings: InstanceSettings::default(),
|
||||||
port: 1312,
|
port: 1312,
|
||||||
|
address: IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ pub mod configuration;
|
||||||
|
|
||||||
use configuration::ConfigError;
|
use configuration::ConfigError;
|
||||||
|
|
||||||
|
use std::net::SocketAddr;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
|
@ -178,9 +179,9 @@ async fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
async fn start_server(config: configuration::Conf) -> std::io::Result<()> {
|
async fn start_server(config: configuration::Conf) -> std::io::Result<()> {
|
||||||
// Where we binding bois
|
// Where we binding bois
|
||||||
let bind = format!("0.0.0.0:{}", config.port);
|
let socket_addr = SocketAddr::new(config.address, config.port);
|
||||||
|
|
||||||
println!("Starting pronouns-today-web on {}", &bind);
|
println!("Starting pronouns-today-web on {}", &socket_addr);
|
||||||
HttpServer::new(move|| {
|
HttpServer::new(move|| {
|
||||||
let logger = Logger::default();
|
let logger = Logger::default();
|
||||||
let app = App::new()
|
let app = App::new()
|
||||||
|
@ -204,7 +205,7 @@ async fn start_server(config: configuration::Conf) -> std::io::Result<()> {
|
||||||
.service(resource("/{name}/{prefs}").to(handle_basic_request))
|
.service(resource("/{name}/{prefs}").to(handle_basic_request))
|
||||||
.default_service(web::to(not_found))
|
.default_service(web::to(not_found))
|
||||||
})
|
})
|
||||||
.bind(&bind)?
|
.bind(&socket_addr)?
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue