Feature: Unix domain socket support (#492)
Co-authored-by: Khanh Ngo <k@ndk.name>
This commit is contained in:
		
							parent
							
								
									47fac2b49b
								
							
						
					
					
						commit
						e73047b14f
					
				|  | @ -21,6 +21,9 @@ node_modules/ | ||||||
| .vscode | .vscode | ||||||
| .idea | .idea | ||||||
| 
 | 
 | ||||||
|  | # Vim | ||||||
|  | .*.sw[op] | ||||||
|  | 
 | ||||||
| # Examples | # Examples | ||||||
| examples/docker-compose/config | examples/docker-compose/config | ||||||
| examples/docker-compose/db | examples/docker-compose/db | ||||||
|  |  | ||||||
|  | @ -39,7 +39,7 @@ docker-compose up | ||||||
| | Variable                    | Description                                                                                                                                                                 | Default                            | | | Variable                    | Description                                                                                                                                                                 | Default                            | | ||||||
| |-----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------| | |-----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------| | ||||||
| | `BASE_PATH`                 | Set this variable if you run wireguard-ui under a subpath of your reverse proxy virtual host (e.g. /wireguard)                                                              | N/A                                | | | `BASE_PATH`                 | Set this variable if you run wireguard-ui under a subpath of your reverse proxy virtual host (e.g. /wireguard)                                                              | N/A                                | | ||||||
| | `BIND_ADDRESS`              | The addresses that can access to the web interface and the port                                                                                                             | 0.0.0.0:80                         | | | `BIND_ADDRESS`              | The addresses that can access to the web interface and the port, use unix:///abspath/to/file.socket for unix domain socket.                                                 | 0.0.0.0:80                         | | ||||||
| | `SESSION_SECRET`            | The secret key used to encrypt the session cookies. Set this to a random value                                                                                              | N/A                                | | | `SESSION_SECRET`            | The secret key used to encrypt the session cookies. Set this to a random value                                                                                              | N/A                                | | ||||||
| | `SESSION_SECRET_FILE`       | Optional filepath for the secret key used to encrypt the session cookies. Leave `SESSION_SECRET` blank to take effect                                                       | N/A                                | | | `SESSION_SECRET_FILE`       | Optional filepath for the secret key used to encrypt the session cookies. Leave `SESSION_SECRET` blank to take effect                                                       | N/A                                | | ||||||
| | `WGUI_USERNAME`             | The username for the login page. Used for db initialization only                                                                                                            | `admin`                            | | | `WGUI_USERNAME`             | The username for the login page. Used for db initialization only                                                                                                            | `admin`                            | | ||||||
|  |  | ||||||
							
								
								
									
										16
									
								
								main.go
								
								
								
								
							
							
						
						
									
										16
									
								
								main.go
								
								
								
								
							|  | @ -8,6 +8,9 @@ import ( | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"os" | 	"os" | ||||||
| 	"time" | 	"time" | ||||||
|  | 	"strings" | ||||||
|  | 	"net" | ||||||
|  | 	"syscall" | ||||||
| 
 | 
 | ||||||
| 	"github.com/labstack/echo/v4" | 	"github.com/labstack/echo/v4" | ||||||
| 	"github.com/labstack/gommon/log" | 	"github.com/labstack/gommon/log" | ||||||
|  | @ -229,7 +232,20 @@ func main() { | ||||||
| 	// serves other static files
 | 	// serves other static files
 | ||||||
| 	app.GET(util.BasePath+"/static/*", echo.WrapHandler(http.StripPrefix(util.BasePath+"/static/", assetHandler))) | 	app.GET(util.BasePath+"/static/*", echo.WrapHandler(http.StripPrefix(util.BasePath+"/static/", assetHandler))) | ||||||
| 
 | 
 | ||||||
|  | 	if strings.HasPrefix(util.BindAddress, "unix://") { | ||||||
|  | 		// Listen on unix domain socket.
 | ||||||
|  | 		// https://github.com/labstack/echo/issues/830
 | ||||||
|  | 		syscall.Unlink(util.BindAddress[6:]) | ||||||
|  | 		l, err := net.Listen("unix", util.BindAddress[6:]) | ||||||
|  | 		if err != nil { | ||||||
|  | 			app.Logger.Fatal(err) | ||||||
|  | 		} | ||||||
|  | 		app.Listener = l | ||||||
|  | 		app.Logger.Fatal(app.Start("")) | ||||||
|  | 	} else { | ||||||
|  | 		// Listen on TCP socket
 | ||||||
| 		app.Logger.Fatal(app.Start(util.BindAddress)) | 		app.Logger.Fatal(app.Start(util.BindAddress)) | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func initServerConfig(db store.IStore, tmplDir fs.FS) { | func initServerConfig(db store.IStore, tmplDir fs.FS) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue