mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-11-05 16:45:44 +00:00
feat: add support for listening on unix sockets
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user