Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ server_name = "My OpenFusion Server"
public_url = "api.example.xyz"
db_path = "../OpenFusion/database.db"
template_dir = "./templates"
bind_ip = "0.0.0.0"
port = 8888

[tls]
Expand Down
13 changes: 8 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, net::SocketAddr, sync::Arc};
use std::{collections::HashMap, net::SocketAddr, net::IpAddr, sync::Arc};

use ::ring::rand::SystemRandom;
use axum::{extract::State, routing::get, Json, Router};
Expand Down Expand Up @@ -32,6 +32,7 @@ struct CoreConfig {
public_url: String,
db_path: String,
template_dir: String,
bind_ip: String,
port: Option<u16>,
}

Expand Down Expand Up @@ -162,11 +163,11 @@ async fn main() {
let _ = tokio::join!(http, https);
}

const BIND_IP: [u8; 4] = [127, 0, 0, 1];

async fn init_http(routes: Router<Arc<AppState>>, config: &Config, state: AppState) {
const DEFAULT_HTTP_PORT: u16 = 80;
let addr = SocketAddr::from((BIND_IP, config.core.port.unwrap_or(DEFAULT_HTTP_PORT)));
let addr = SocketAddr::from((
config.core.bind_ip.parse::<IpAddr>().expect("Failed to parse bind_ip"),
config.core.port.unwrap_or(DEFAULT_HTTP_PORT)));

let app = routes.with_state(Arc::new(state));

Expand All @@ -186,7 +187,9 @@ async fn init_https(routes: Router<Arc<AppState>>, config: &Config, mut state: A
return;
};

let addr = SocketAddr::from((BIND_IP, tls_config.port.unwrap_or(DEFAULT_HTTPS_PORT)));
let addr = SocketAddr::from((
config.core.bind_ip.parse::<IpAddr>().expect("Failed to parse bind_ip"),
tls_config.port.unwrap_or(DEFAULT_HTTPS_PORT)));

#[cfg(not(feature = "tls"))]
{
Expand Down