feat: listen 0.0.0.0 by default
This commit is contained in:
parent
c3dd0f0ec5
commit
9dda55b7c8
3 changed files with 13 additions and 34 deletions
18
README.md
18
README.md
|
@ -28,6 +28,12 @@ Duf is a fully functional file server.
|
||||||
cargo install duf
|
cargo install duf
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### With docker
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run -v /tmp:/tmp -p 5000:5000 --rm -it docker.io/sigoden/duf /tmp
|
||||||
|
```
|
||||||
|
|
||||||
### Binaries on macOS, Linux, Windows
|
### Binaries on macOS, Linux, Windows
|
||||||
|
|
||||||
Download from [Github Releases](https://github.com/sigoden/duf/releases), unzip and add duf to your $PATH.
|
Download from [Github Releases](https://github.com/sigoden/duf/releases), unzip and add duf to your $PATH.
|
||||||
|
@ -50,7 +56,7 @@ OPTIONS:
|
||||||
--allow-delete Allow delete files/folders
|
--allow-delete Allow delete files/folders
|
||||||
--allow-symlink Allow symlink to files/folders outside root directory
|
--allow-symlink Allow symlink to files/folders outside root directory
|
||||||
--allow-upload Allow upload files/folders
|
--allow-upload Allow upload files/folders
|
||||||
-b, --bind <address> Specify bind address [default: 127.0.0.1]
|
-b, --bind <address> Specify bind address [default: 0.0.0.0]
|
||||||
--cors Enable CORS, sets `Access-Control-Allow-Origin: *`
|
--cors Enable CORS, sets `Access-Control-Allow-Origin: *`
|
||||||
-h, --help Print help information
|
-h, --help Print help information
|
||||||
-p, --port <port> Specify port to listen on [default: 5000]
|
-p, --port <port> Specify port to listen on [default: 5000]
|
||||||
|
@ -76,18 +82,10 @@ duf
|
||||||
duf folder_name
|
duf folder_name
|
||||||
```
|
```
|
||||||
|
|
||||||
Listen on all Interfaces and port 3000
|
|
||||||
|
|
||||||
```
|
|
||||||
duf -b 0.0.0.0 -p 3000
|
|
||||||
```
|
|
||||||
|
|
||||||
Allow all operations such as upload, delete
|
Allow all operations such as upload, delete
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
duf --allow-all
|
duf --allow-all
|
||||||
# or
|
|
||||||
duf -A
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Only allow upload operation
|
Only allow upload operation
|
||||||
|
@ -102,7 +100,7 @@ Serve a single page application (SPA)
|
||||||
duf --render-spa
|
duf --render-spa
|
||||||
```
|
```
|
||||||
|
|
||||||
Serve https
|
Use https
|
||||||
|
|
||||||
```
|
```
|
||||||
duf --tls-cert my.crt --tls-key my.key
|
duf --tls-cert my.crt --tls-key my.key
|
||||||
|
|
21
src/args.rs
21
src/args.rs
|
@ -16,7 +16,7 @@ fn app() -> clap::Command<'static> {
|
||||||
Arg::new("address")
|
Arg::new("address")
|
||||||
.short('b')
|
.short('b')
|
||||||
.long("bind")
|
.long("bind")
|
||||||
.default_value("127.0.0.1")
|
.default_value("0.0.0.0")
|
||||||
.help("Specify bind address")
|
.help("Specify bind address")
|
||||||
.value_name("address"),
|
.value_name("address"),
|
||||||
)
|
)
|
||||||
|
@ -173,7 +173,7 @@ impl Args {
|
||||||
fn parse_path<P: AsRef<Path>>(path: P) -> BoxResult<PathBuf> {
|
fn parse_path<P: AsRef<Path>>(path: P) -> BoxResult<PathBuf> {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
bail!("error: path \"{}\" doesn't exist", path.display());
|
return Err(format!("Path `{}` doesn't exist", path.display()).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
env::current_dir()
|
env::current_dir()
|
||||||
|
@ -181,27 +181,14 @@ impl Args {
|
||||||
p.push(path); // If path is absolute, it replaces the current path.
|
p.push(path); // If path is absolute, it replaces the current path.
|
||||||
std::fs::canonicalize(p)
|
std::fs::canonicalize(p)
|
||||||
})
|
})
|
||||||
.or_else(|err| {
|
.map_err(|err| format!("Failed to access path `{}`: {}", path.display(), err,).into())
|
||||||
bail!(
|
|
||||||
"error: failed to access path \"{}\": {}",
|
|
||||||
path.display(),
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct socket address from arguments.
|
/// Construct socket address from arguments.
|
||||||
pub fn address(&self) -> BoxResult<SocketAddr> {
|
pub fn address(&self) -> BoxResult<SocketAddr> {
|
||||||
format!("{}:{}", self.address, self.port)
|
format!("{}:{}", self.address, self.port)
|
||||||
.parse()
|
.parse()
|
||||||
.or_else(|err| {
|
.map_err(|_| format!("Invalid bind address `{}:{}`", self.address, self.port).into())
|
||||||
bail!(
|
|
||||||
"error: invalid address {}:{} : {}",
|
|
||||||
self.address,
|
|
||||||
self.port,
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
macro_rules! bail {
|
|
||||||
($($tt:tt)*) => {
|
|
||||||
return Err(From::from(format!($($tt)*)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod args;
|
mod args;
|
||||||
mod server;
|
mod server;
|
||||||
|
|
||||||
|
@ -23,6 +17,6 @@ async fn run() -> BoxResult<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_err<T>(err: Box<dyn std::error::Error>) -> T {
|
fn handle_err<T>(err: Box<dyn std::error::Error>) -> T {
|
||||||
eprintln!("Server error: {}", err);
|
eprintln!("error: {}", err);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue