diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 4f023ddc..84050b95 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -32,8 +32,5 @@ RUN cp -rp /etc/nginx /etc/nginx.orig # Set PATH to include Go installation and default go install binary location ENV PATH="/usr/local/go/bin:/root/go/bin:${PATH}" -# Install air with go install (requires Go 1.23 or higher) -RUN go install github.com/air-verse/air@latest - # set zsh as default shell RUN chsh -s $(which zsh) diff --git a/.devcontainer/init-nginx.sh b/.devcontainer/init-nginx.sh index 361f8831..65f0aae0 100755 --- a/.devcontainer/init-nginx.sh +++ b/.devcontainer/init-nginx.sh @@ -1,3 +1,4 @@ +#!/bin/bash # init nginx config dir if [ "$(ls -A /etc/nginx)" = "" ]; then echo "Initialing Nginx config dir" @@ -5,5 +6,51 @@ if [ "$(ls -A /etc/nginx)" = "" ]; then echo "Initialed Nginx config dir" fi + +src_dir="/usr/share/nginx/modules-available" +dest_dir="/etc/nginx/modules-enabled" + +create_symlink() { + local module_name=$1 + local weight=$2 + + local target="$dest_dir/$weight-$module_name" + local source="$src_dir/$module_name" + + ln -sf "$source" "$target" + echo "Created symlink: $target -> $source" +} + +modules=( + "mod-http-ndk.conf 10" + "mod-http-auth-pam.conf 50" + "mod-http-cache-purge.conf 50" + "mod-http-dav-ext.conf 50" + "mod-http-echo.conf 50" + "mod-http-fancyindex.conf 50" + "mod-http-geoip.conf 50" + "mod-http-geoip2.conf 50" + "mod-http-headers-more-filter.conf 50" + "mod-http-image-filter.conf 50" + "mod-http-lua.conf 50" + "mod-http-perl.conf 50" + "mod-http-subs-filter.conf 50" + "mod-http-uploadprogress.conf 50" + "mod-http-upstream-fair.conf 50" + "mod-http-xslt-filter.conf 50" + "mod-mail.conf 50" + "mod-nchan.conf 50" + "mod-stream.conf 50" + "mod-stream-geoip.conf 70" + "mod-stream-geoip2.conf 70" +) + +for module in "${modules[@]}"; do + module_name=$(echo $module | awk '{print $1}') + weight=$(echo $module | awk '{print $2}') + + create_symlink "$module_name" "$weight" +done + # start nginx nginx diff --git a/api/nginx/control.go b/api/nginx/control.go index 6426584d..57f48006 100644 --- a/api/nginx/control.go +++ b/api/nginx/control.go @@ -5,14 +5,16 @@ import ( "github.com/0xJacky/Nginx-UI/internal/nginx" "github.com/gin-gonic/gin" - "github.com/uozi-tech/cosy" ) // Reload reloads the nginx func Reload(c *gin.Context) { output, err := nginx.Reload() if err != nil { - cosy.ErrHandler(c, err) + c.JSON(http.StatusInternalServerError, gin.H{ + "message": output + err.Error(), + "level": nginx.GetLogLevel(output), + }) return } c.JSON(http.StatusOK, gin.H{ @@ -25,7 +27,10 @@ func Reload(c *gin.Context) { func TestConfig(c *gin.Context) { output, err := nginx.TestConfig() if err != nil { - cosy.ErrHandler(c, err) + c.JSON(http.StatusInternalServerError, gin.H{ + "message": output + err.Error(), + "level": nginx.GetLogLevel(output), + }) return } c.JSON(http.StatusOK, gin.H{ @@ -46,7 +51,10 @@ func Restart(c *gin.Context) { func Status(c *gin.Context) { lastOutput, err := nginx.GetLastOutput() if err != nil { - cosy.ErrHandler(c, err) + c.JSON(http.StatusInternalServerError, gin.H{ + "message": lastOutput + err.Error(), + "level": nginx.GetLogLevel(lastOutput), + }) return }