checkrr: [BUG] Issue with subdirectory in baseurl
Describe the bug webserver from yaml file, this is json with yamlencoding (terraform)
"webserver" : {
"port" : 8585,
"baseurl" : "/checkrr"
},
My Ingress for this service checkrr.example.com/checkrr is essentially what it resolves too.
domain_match_pattern = "Host(`checkrr.${var.cloudflare_config.zone_name}`) && PathPrefix(`/checkrr`)"
The static site itself doesn’t even load just 404, but the api responses don’t have the directory delimiter “checkrr/api” between the baseurl and api routes, if you change baseurl to /checkrr/ the api works static site does not.
The issue atleast for the api is on line 84 webserver.go router.Group(w.BaseURL + "api")
= /checkrrapi NOT /checkrr/api
To Reproduce Steps to reproduce the behavior:
- Change baseurl to /checkrr
- go to http://localhost:8585/checkrrapi/files/bad
- You will see the api response
Expected behavior I want subdirectories for my services so I would want the UI & api both to work when changing the baseurl from the default /
Screenshots
Desktop (please complete the following information):
- OS: windows
- Browser: chrome
Checkrr version 3.1.4
Commit: 1daa66a29265db10eb86081e5423af7cf16515a3
Built On: 2023-07-27T00:47:01Z
Built By: goreleaser
Additional context Havent worked with static.Serve from gincontrib at all, but I build golang api’s regularly for work (done gin countless times). I would be willing to do a PR for this issue (I’m sure Ill figure out the static site given enough time)
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 21 (21 by maintainers)
Well, the good news is the vite code is sorted 100%. @hugo-vrijswijk was right, setting base to
./
was the play. The only thing that’s really needed is to make sure the trailing slash is included if the user leaves it off. It can be done with your enforce code whenw.BaseURL
is being set inFromConfig()
for the DRY-est code.All other code I intend to add for 3.2.0 is already in the branch too.
I’m not sure. The path gets hardcoded in compile-time. Maybe if the base-path is set to
./
it might work? As there is only one page in this application it shouldn’t mess with too muchOkay some update on the static side of things,
replacing the static.Serve for
router.StaticFS(w.BaseURL.EnforceTrailingSlash().String(), embeddedBuildFolder)
+base: "/checkrr/",
in thevite.config.js
will successfully host that site from the subdirectory,Problem being as that StaticFS conflicts with EVERY other route under baseURL including API, this was me just trying to figure it out.
I’m out of ideas today on how to fix this further. 😆 but that poses another problem that if baseurl is anything BUT / in the config you need to also update the vite config & yarn build again, There may be runtime env or otherwise you can apply to the docker container not sure not too familiar with vite or frontend dev for that matter 🤣
go-task
andair
would be fine to add tbh! I mostly just spin up and down postgo build
and/oryarn build
as needed, but if it makes the repo more approachable, then it’s probably for the best.