@@ -21,7 +21,6 @@ use axum::{
21
21
use serde:: Serialize ;
22
22
use serde_json:: Value ;
23
23
use std:: {
24
- net:: SocketAddr ,
25
24
sync:: { Arc , Mutex } ,
26
25
} ;
27
26
use tower_http:: services:: ServeDir ;
@@ -33,9 +32,6 @@ async fn main() {
33
32
// TODO: Instrument handlers & DB code.
34
33
tracing_subscriber:: fmt:: init ( ) ;
35
34
36
- // TODO: make this configurable at runtime
37
- let addr = SocketAddr :: from ( ( [ 127 , 0 , 0 , 1 ] , 3032 ) ) ;
38
- println ! ( "listening on {}" , addr) ;
39
35
40
36
let datastore = initialize_datastore ( ) . expect ( "Error initializing datastore" ) ;
41
37
@@ -57,6 +53,9 @@ async fn main() {
57
53
. nest ( "/files/" , on_service ( MethodFilter :: GET , files_service) )
58
54
. layer ( Extension ( datastore) ) ;
59
55
56
+ let addr = listen_addr ( ) ;
57
+ println ! ( "listening on {}" , addr) ;
58
+
60
59
axum:: Server :: bind ( & addr)
61
60
. serve ( app. into_make_service ( ) )
62
61
. await
@@ -72,6 +71,19 @@ fn initialize_datastore() -> AppResult<DataStore> {
72
71
Ok ( Arc :: new ( Mutex :: new ( tiddlers) ) )
73
72
}
74
73
74
+ /// Determine the network port to bind from the CLI (or use 127.0.0.1:3032 by
75
+ /// default).
76
+ fn listen_addr ( ) -> std:: net:: SocketAddr {
77
+ // TODO(nknight): Replace this with a propper CLI using something like seahorse
78
+ use std:: net:: SocketAddr ;
79
+ use std:: env:: args;
80
+
81
+ if let Some ( src) = args ( ) . nth ( 1 ) {
82
+ src. parse :: < SocketAddr > ( ) . expect ( & format ! ( "Couldn't parse a socket from {}" , src) )
83
+ } else {
84
+ SocketAddr :: from ( ( [ 127 , 0 , 0 , 1 ] , 3032 ) ) }
85
+ }
86
+
75
87
// -----------------------------------------------------------------------------------
76
88
// Views
77
89
0 commit comments