feat: add support for listening on unix sockets

This commit is contained in:
Stavros
2025-11-04 18:42:04 +02:00
parent 6ac9f6ed4e
commit 60dada86a6
4 changed files with 31 additions and 1 deletions

View File

@@ -70,6 +70,7 @@ func (c *rootCmd) Register() {
{"trusted-proxies", "", "Comma separated list of trusted proxies (IP addresses or CIDRs) for correct client IP detection."}, {"trusted-proxies", "", "Comma separated list of trusted proxies (IP addresses or CIDRs) for correct client IP detection."},
{"disable-analytics", false, "Disable anonymous version collection."}, {"disable-analytics", false, "Disable anonymous version collection."},
{"disable-resources", false, "Disable the resources server."}, {"disable-resources", false, "Disable the resources server."},
{"socket-path", "", "Path to the Unix socket to bind the server to."},
} }
for _, opt := range configOptions { for _, opt := range configOptions {

View File

@@ -286,6 +286,26 @@ func (app *BootstrapApp) Setup() error {
log.Debug().Msg("Starting database cleanup routine") log.Debug().Msg("Starting database cleanup routine")
go app.dbCleanup(database) go app.dbCleanup(database)
// If we have an socket path, bind to it
if app.config.SocketPath != "" {
// Remove existing socket file
if _, err := os.Stat(app.config.SocketPath); err == nil {
log.Info().Msgf("Removing existing socket file %s", app.config.SocketPath)
err := os.Remove(app.config.SocketPath)
if err != nil {
return fmt.Errorf("failed to remove existing socket file: %w", err)
}
}
// Start server with unix socket
log.Info().Msgf("Starting server on unix socket %s", app.config.SocketPath)
if err := engine.RunUnix(app.config.SocketPath); err != nil {
log.Fatal().Err(err).Msg("Failed to start server")
}
return nil
}
// Start server // Start server
address := fmt.Sprintf("%s:%d", app.config.Address, app.config.Port) address := fmt.Sprintf("%s:%d", app.config.Address, app.config.Port)
log.Info().Msgf("Starting server on %s", address) log.Info().Msgf("Starting server on %s", address)

View File

@@ -41,6 +41,7 @@ type Config struct {
TrustedProxies string `mapstructure:"trusted-proxies"` TrustedProxies string `mapstructure:"trusted-proxies"`
DisableAnalytics bool `mapstructure:"disable-analytics"` DisableAnalytics bool `mapstructure:"disable-analytics"`
DisableResources bool `mapstructure:"disable-resources"` DisableResources bool `mapstructure:"disable-resources"`
SocketPath string `mapstructure:"socket-path"`
} }
// OAuth/OIDC config // OAuth/OIDC config

View File

@@ -97,7 +97,15 @@ func (controller *ContextController) userContextHandler(c *gin.Context) {
} }
func (controller *ContextController) appContextHandler(c *gin.Context) { func (controller *ContextController) appContextHandler(c *gin.Context) {
appUrl, _ := url.Parse(controller.config.AppURL) // no need to check error, validated on startup appUrl, err := url.Parse(controller.config.AppURL)
if err != nil {
log.Error().Err(err).Msg("Failed to parse app URL")
c.JSON(500, gin.H{
"status": 500,
"message": "Internal Server Error",
})
return
}
c.JSON(200, AppContextResponse{ c.JSON(200, AppContextResponse{
Status: 200, Status: 200,