Skip to content

Commit aa33ba9

Browse files
committed
Default base_url to socket address, instead of 127.0.0.1
1 parent d99b98d commit aa33ba9

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/cli.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ pub enum Command {
7171
force: bool,
7272

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

7777
/// Include drafts when loading the site
7878
#[clap(long)]

src/cmd/serve.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -325,17 +325,26 @@ fn create_new_site(
325325
interface_port: u16,
326326
output_dir: Option<&Path>,
327327
force: bool,
328-
base_url: &str,
328+
base_url: Option<&str>,
329329
config_file: &Path,
330330
include_drafts: bool,
331-
no_port_append: bool,
331+
mut no_port_append: bool,
332332
ws_port: Option<u16>,
333333
) -> Result<(Site, SocketAddr)> {
334334
SITE_CONTENT.write().unwrap().clear();
335335

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

339+
// if no base URL provided, use socket address
340+
let base_url = base_url.map_or_else(
341+
|| {
342+
no_port_append = true;
343+
address.to_string()
344+
},
345+
|u| u.to_string(),
346+
);
347+
339348
let base_url = if base_url == "/" {
340349
String::from("/")
341350
} else {
@@ -385,7 +394,7 @@ pub fn serve(
385394
interface_port: u16,
386395
output_dir: Option<&Path>,
387396
force: bool,
388-
base_url: &str,
397+
base_url: Option<&str>,
389398
config_file: &Path,
390399
open: bool,
391400
include_drafts: bool,

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn main() {
106106
port,
107107
output_dir.as_deref(),
108108
force,
109-
&base_url,
109+
base_url.as_deref(),
110110
&config_file,
111111
open,
112112
drafts,

0 commit comments

Comments
 (0)