diff --git a/docs/source/config.rst b/docs/source/config.rst index fc83ef137..b68268fa1 100644 --- a/docs/source/config.rst +++ b/docs/source/config.rst @@ -25,8 +25,8 @@ Server Configuration ~~~~~~~~~~~~~~~~~~ - ``DAGU_HOST`` (``127.0.0.1``): Server binding host - ``DAGU_PORT`` (``8080``): Server binding port -- ``DAGU_BASE_PATH`` (``""``): Base path to serve the application -- ``DAGU_TZ`` (``""``): Server timezone (default: system timezone) +- ``DAGU_BASE_PATH`` (``""``): Base path to serve the application (e.g., ``/dagu``) +- ``DAGU_TZ`` (``""``): Server timezone (default: system timezone, e.g., ``Asia/Tokyo``) - ``DAGU_CERT_FILE``: SSL certificate file path - ``DAGU_KEY_FILE``: SSL key file path diff --git a/docs/source/scheduler.rst b/docs/source/scheduler.rst index b1f6710be..0a5976d3e 100644 --- a/docs/source/scheduler.rst +++ b/docs/source/scheduler.rst @@ -28,7 +28,7 @@ Or you can set multiple schedules. - name: scheduled job command: job.sh -You can also specify a cron expression to run within a specific timezone. See `list of tz database timezones ` +You can also specify a cron expression to run within a specific timezone. See `list of tz database timezones `_ .. code-block:: yaml diff --git a/internal/frontend/middleware/global.go b/internal/frontend/middleware/global.go index dc4df0fb8..e7d215851 100644 --- a/internal/frontend/middleware/global.go +++ b/internal/frontend/middleware/global.go @@ -101,19 +101,25 @@ func Setup(opts *Options) { } func prefixChecker(next http.Handler) http.Handler { + handleRequest := func(w http.ResponseWriter, r *http.Request) { + if strings.HasPrefix(r.URL.Path, "/api") { + next.ServeHTTP(w, r) + } else { + defaultHandler.ServeHTTP(w, r) + } + } return http.HandlerFunc( func(w http.ResponseWriter, r *http.Request) { + if basePath == "" || !strings.HasPrefix(r.URL.Path, basePath) { + handleRequest(w, r) + return + } if basePath != "" && r.URL.Path == "/" { http.Redirect(w, r, basePath, http.StatusSeeOther) return } - http.StripPrefix(basePath, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if strings.HasPrefix(r.URL.Path, "/api") { - next.ServeHTTP(w, r) - } else { - defaultHandler.ServeHTTP(w, r) - } + handleRequest(w, r) })).ServeHTTP(w, r) }) }