@@ -22,6 +22,7 @@ import (
22
22
"github.com/artyom/autoflags"
23
23
"github.com/fsnotify/fsnotify"
24
24
"github.com/joho/godotenv"
25
+ "github.com/kabukky/httpscerts"
25
26
"github.com/kardianos/service"
26
27
"github.com/mholt/certmagic"
27
28
yaml "gopkg.in/yaml.v2"
@@ -52,6 +53,7 @@ type runArgs struct {
52
53
HostName string `flag:"hostname,The default host name to be used with any and / prefix options"`
53
54
Email string `flag:"email,Contact email address presented to letsencrypt CA"`
54
55
Staging bool `flag:"staging,Use the letsencrypt staging server"`
56
+ SelfSign bool `flag:"selfsign,Use a self-signed certificate for HTTPS instead letsencrypt"`
55
57
Install bool `flag:"install,Installs as a windows service"`
56
58
Remove bool `flag:"remove,Removes the windows service"`
57
59
Debug bool `flag:"debug,Log the file path of requests"`
@@ -264,6 +266,27 @@ func run() error {
264
266
Addr : args .Addr ,
265
267
}
266
268
return srv .ListenAndServe ()
269
+ } else if args .SelfSign {
270
+ // Use the first mapping for the host name
271
+ hostname := "localhost"
272
+ for k := range mapping {
273
+ hostname = k
274
+ break
275
+ }
276
+ hostname = strings .ToLower (hostname )
277
+ // Use self-signed certificate instead of letsencrypt
278
+ certPath := filepath .Join (args .CacheDir , "self-signed-" + hostname + "-cert.pem" )
279
+ keyPath := filepath .Join (args .CacheDir , "self-signed-" + hostname + "-key.pem" )
280
+ err := httpscerts .Check (certPath , keyPath )
281
+ // If they are not available, generate new ones.
282
+ if err != nil {
283
+
284
+ err = httpscerts .Generate (certPath , keyPath , hostname )
285
+ if err != nil {
286
+ return err
287
+ }
288
+ }
289
+ return http .ListenAndServeTLS (":443" , certPath , keyPath , & proxy )
267
290
}
268
291
269
292
// Read and agree to your CA's legal documents
0 commit comments