mirror of
https://github.com/h44z/wg-portal
synced 2025-06-26 18:16:21 +00:00
Added TLS support for web
- Added optional configurations `cert_file` and `key_file` to run web server with https Signed-off-by: Dmytro Bondar <git@bonddim.com>
This commit is contained in:
parent
a46dabc1d3
commit
b30fb72a91
@ -143,7 +143,8 @@ The following configuration options are available:
|
||||
| csrf_secret | web | extremely_secret | The CSRF secret. |
|
||||
| site_title | web | WireGuard Portal | The title that is shown in the web frontend. |
|
||||
| site_company_name | web | WireGuard Portal | The company name that is shown at the bottom of the web frontend. |
|
||||
|
||||
| cert_file | web | | (Optional) Path to the TLS certificate file |
|
||||
| key_file | web | | (Optional) Path to the TLS certificate key file |
|
||||
|
||||
## Upgrading from V1
|
||||
|
||||
|
@ -68,8 +68,7 @@ func NewServer(cfg *config.Config, endpoints ...ApiEndpointSetupFunc) (*Server,
|
||||
c.Writer.Header().Set("X-Served-By", hostname)
|
||||
c.Next()
|
||||
}).Use(func(c *gin.Context) {
|
||||
var xRequestID string
|
||||
xRequestID = uuid(16)
|
||||
xRequestID := uuid(16)
|
||||
|
||||
c.Request.Header.Set(RequestIDKey, xRequestID)
|
||||
c.Set(RequestIDKey, xRequestID)
|
||||
@ -106,7 +105,13 @@ func (s *Server) Run(ctx context.Context, listenAddress string) {
|
||||
|
||||
srvContext, cancelFn := context.WithCancel(ctx)
|
||||
go func() {
|
||||
if err := srv.ListenAndServe(); err != nil {
|
||||
var err error
|
||||
if s.cfg.Web.CertFile != "" && s.cfg.Web.KeyFile != "" {
|
||||
err = srv.ListenAndServeTLS(s.cfg.Web.CertFile, s.cfg.Web.KeyFile)
|
||||
} else {
|
||||
err = srv.ListenAndServe()
|
||||
}
|
||||
if err != nil {
|
||||
logrus.Infof("web service on %s exited: %v", listenAddress, err)
|
||||
cancelFn()
|
||||
}
|
||||
|
@ -9,4 +9,6 @@ type WebConfig struct {
|
||||
CsrfSecret string `yaml:"csrf_secret"`
|
||||
SiteTitle string `yaml:"site_title"`
|
||||
SiteCompanyName string `yaml:"site_company_name"`
|
||||
CertFile string `yaml:"cert_file"`
|
||||
KeyFile string `yaml:"key_file"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user