Skip to content

Commit

Permalink
Default base_url to socket address, instead of 127.0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
clarfonthey committed Dec 30, 2023
1 parent d99b98d commit aa33ba9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pub enum Command {
force: bool,

/// Changes the base_url
#[clap(short = 'u', long, default_value = "127.0.0.1")]
base_url: String,
#[clap(short = 'u', long)]
base_url: Option<String>,

/// Include drafts when loading the site
#[clap(long)]
Expand Down
15 changes: 12 additions & 3 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,26 @@ fn create_new_site(
interface_port: u16,
output_dir: Option<&Path>,
force: bool,
base_url: &str,
base_url: Option<&str>,
config_file: &Path,
include_drafts: bool,
no_port_append: bool,
mut no_port_append: bool,
ws_port: Option<u16>,
) -> Result<(Site, SocketAddr)> {
SITE_CONTENT.write().unwrap().clear();

let mut site = Site::new(root_dir, config_file)?;
let address = SocketAddr::new(interface, interface_port);

// if no base URL provided, use socket address
let base_url = base_url.map_or_else(
|| {
no_port_append = true;
address.to_string()
},
|u| u.to_string(),
);

let base_url = if base_url == "/" {
String::from("/")
} else {
Expand Down Expand Up @@ -385,7 +394,7 @@ pub fn serve(
interface_port: u16,
output_dir: Option<&Path>,
force: bool,
base_url: &str,
base_url: Option<&str>,
config_file: &Path,
open: bool,
include_drafts: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn main() {
port,
output_dir.as_deref(),
force,
&base_url,
base_url.as_deref(),
&config_file,
open,
drafts,
Expand Down

0 comments on commit aa33ba9

Please sign in to comment.