@@ -115,6 +115,9 @@ func main() {
115115 addParameter (flags , "disable-cors" , "" , false , "Disable CORS headers" )
116116 addParameter (flags , "header" , "H" , "" , "Add a custom header when fetching API" )
117117 addParameter (flags , "add-server" , "" , "" , "Add a new valid server URL, use with --validate-server" )
118+ addParameter (flags , "https" , "" , false , "Use HTTPS instead of HTTP" )
119+ addParameter (flags , "public-key" , "" , "" , "Public key for HTTPS, use with --https" )
120+ addParameter (flags , "private-key" , "" , "" , "Private key for HTTPS, use with --https" )
118121
119122 // Run the app!
120123 root .Execute ()
@@ -607,7 +610,11 @@ func server(cmd *cobra.Command, args []string) {
607610 w .Write (encoded )
608611 })
609612
610- fmt .Printf ("🌱 Sprouting %s on port %d" , swagger .Info .Title , viper .GetInt ("port" ))
613+ format := "🌱 Sprouting %s on port %d"
614+ if viper .GetBool ("https" ) {
615+ format = "🌱 Securely sprouting %s on port %d"
616+ }
617+ fmt .Printf (format , swagger .Info .Title , viper .GetInt ("port" ))
611618
612619 if viper .GetBool ("validate-server" ) && len (swagger .Servers ) != 0 {
613620 fmt .Printf (" with valid servers:\n " )
@@ -618,5 +625,11 @@ func server(cmd *cobra.Command, args []string) {
618625 fmt .Printf ("\n " )
619626 }
620627
621- http .ListenAndServe (fmt .Sprintf (":%d" , viper .GetInt ("port" )), nil )
628+ port := fmt .Sprintf (":%d" , viper .GetInt ("port" ))
629+ if viper .GetBool ("https" ) {
630+ err = http .ListenAndServeTLS (port , viper .GetString ("public-key" ),
631+ viper .GetString ("private-key" ), nil )
632+ } else {
633+ err = http .ListenAndServe (port , nil )
634+ }
622635}
0 commit comments