Skip to content

web: fix frontend assets behind reverse-proxy subpaths - #8384

Merged
unknwon merged 3 commits into
gogs:mainfrom
duytbp:fix/reverse-proxy-subpaths
Jul 12, 2026
Merged

unknwon merged 3 commits into
gogs:mainfrom
duytbp:fix/reverse-proxy-subpaths

Conversation

@duytbp

@duytbp duytbp commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Describe the pull request

Fixes #8385.

This change makes production frontend assets work behind a prefix-stripping reverse proxy and updates the Caddy subpath example.

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code and provided the test plan below.
  • I have added an entry to CHANGELOG.

Test plan

  1. Serve Gogs under /gogs using the Caddy configuration documented in this PR.
  2. Confirm JavaScript, CSS, fonts, and workers load successfully from /gogs/assets/.
  3. Run moon run gogs:test.
  4. Run go test -tags=prod ./cmd/gogs/internal/web.
  5. Run moon run web:lint and moon run web:build.

@unknwon unknwon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

However it seems too many related changes bundled together. If you wanna land this PR, I think only the changes in cmd/gogs/internal/web/webapp_prod.go is needed?

Comment thread cmd/gogs/internal/web/web.go Resolved
Comment thread docs/fine-tuning/reverse-proxy.mdx Resolved

@duytbp duytbp left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look. I updated the Caddy heading and reorganized the tests.

I tested limiting the fix to webapp_prod.go, but that only fixes the backend side. The complete flow has three parts:

  • vite.config.ts makes URLs inside the generated CSS and JavaScript relative. Without this, fonts and workers still request /assets/... and bypass /gogs/*.
  • web.go gives the main JavaScript and CSS entrypoints a stable /gogs/assets/... URL. Without this, opening a deeper page directly can resolve them under the wrong path.
  • webapp_prod.go serves those requests after the proxy strips /gogs, leaving Gogs with /assets/....

Each change handles a different stage of the same asset request, so removing any one leaves part of the frontend broken.

Comment thread docs/fine-tuning/reverse-proxy.mdx Resolved
Comment thread cmd/gogs/internal/web/web.go Resolved
@unknwon

unknwon commented Jul 12, 2026

Copy link
Copy Markdown
Member
  • vite.config.ts makes URLs inside the generated CSS and JavaScript relative. Without this, fonts and workers still request /assets/... and bypass /gogs/*.

I am not sure I follow, aren't /assets/ already replaced with subpath right below your new additions?

@unknwon
unknwon marked this pull request as ready for review July 12, 2026 16:46
@duytbp

duytbp commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Those replacements only run against index.html, so they cover its <script> and <link> tags. They do not rewrite URLs inside the generated CSS or JavaScript.

Without base: "./", font and worker URLs inside those bundles still use /assets/..., which bypasses /gogs/.

@unknwon

unknwon commented Jul 12, 2026

Copy link
Copy Markdown
Member

Those replacements only run against index.html, so they cover its <script> and <link> tags. They do not rewrite URLs inside the generated CSS or JavaScript.

Without base: "./", font and worker URLs inside those bundles still use /assets/..., which bypasses /gogs/.

Ok that makes sense. Now if we use ./assets/, the lines to replace /assets/ can be removed?

@duytbp

duytbp commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Yes, I just verified that the build only uses ./assets/..., so those replacements can be removed.

@duytbp
duytbp force-pushed the fix/reverse-proxy-subpaths branch from c4359ae to 3d8d6d2 Compare July 12, 2026 16:59

@unknwon unknwon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@unknwon
unknwon merged commit f22f322 into gogs:main Jul 12, 2026
8 checks passed
@duytbp
duytbp deleted the fix/reverse-proxy-subpaths branch July 13, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Frontend assets fail when Gogs is served from a reverse-proxy subpath

2 participants