Skip to content

Commit

Permalink
fix: Resolve redirect loop when accessing /dagu through local nginx (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yottahmd authored Nov 19, 2024
1 parent 678dd21 commit 1fb26a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/source/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/source/scheduler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>`
You can also specify a cron expression to run within a specific timezone. See `list of tz database timezones <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>`_

.. code-block:: yaml
Expand Down
18 changes: 12 additions & 6 deletions internal/frontend/middleware/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down

0 comments on commit 1fb26a3

Please sign in to comment.