Individual cert and key paths
This commit is contained in:
parent
8b39e1fca6
commit
c5c8e5d72a
2 changed files with 12 additions and 6 deletions
|
@ -15,7 +15,8 @@ round
|
|||
## Usage
|
||||
|
||||
```
|
||||
--pem-dir <directory> | Directory containing `key.pem` and `cert.pem` files, enables TLS support
|
||||
--cert <path> | Path of `cert.pem` (for TLS)
|
||||
--key <path> | Path of `key.pem` (for TLS)
|
||||
--sock <address> | Bind to the given socket. Defaults to 0.0.0.0:3000.
|
||||
```
|
||||
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -21,10 +21,15 @@ pub type Rng = ChaCha8Rng;
|
|||
|
||||
#[derive(Parser)]
|
||||
pub struct Args {
|
||||
/// Socket to bind to, defaults to 0.0.0.0:3000
|
||||
#[arg(long)]
|
||||
sock: Option<String>,
|
||||
#[arg(long)]
|
||||
pem_dir: Option<PathBuf>,
|
||||
/// Path of the certificate .pem
|
||||
cert: Option<PathBuf>,
|
||||
/// Path of the private key .pem
|
||||
#[arg(long)]
|
||||
key: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -122,15 +127,15 @@ async fn main() {
|
|||
.unwrap_or("0.0.0.0:4000")
|
||||
.parse()
|
||||
.unwrap();
|
||||
if let Some(pem_dir) = args.pem_dir {
|
||||
let config = RustlsConfig::from_pem_file(pem_dir.join("cert.pem"), pem_dir.join("key.pem"))
|
||||
.await
|
||||
.unwrap();
|
||||
if let (Some(cert), Some(key)) = (args.cert, args.key) {
|
||||
println!("Enabling TLS...");
|
||||
let config = RustlsConfig::from_pem_file(cert, key).await.unwrap();
|
||||
bind_rustls(sock, config)
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
} else {
|
||||
println!("WARNING: TLS disabled.");
|
||||
axum_server::bind(sock)
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
|
|
Loading…
Add table
Reference in a new issue