Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: to support --rootpath #3503

Merged
merged 9 commits into from
Apr 29, 2020
Merged

Conversation

mayzhang2000
Copy link
Contributor

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Optional. My organization is added to USERS.md.
  • I've signed the CLA and my build is green (troubleshooting builds).

1. when using https, redirect to the right URL.
2. when rootpath is set, handle healthz, swagger, etc.
@codecov
Copy link

codecov bot commented Apr 28, 2020

Codecov Report

Merging #3503 into master will increase coverage by 0.02%.
The diff coverage is 23.80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3503      +/-   ##
==========================================
+ Coverage   43.04%   43.07%   +0.02%     
==========================================
  Files         183      183              
  Lines       20266    20206      -60     
  Branches      237      273      +36     
==========================================
- Hits         8724     8703      -21     
+ Misses      10538    10497      -41     
- Partials     1004     1006       +2     
Impacted Files Coverage Δ
server/server.go 55.17% <5.88%> (-0.85%) ⬇️
util/swagger/swagger.go 100.00% <100.00%> (ø)
server/application/application.go 28.11% <0.00%> (-0.21%) ⬇️
server/project/util.go 100.00% <0.00%> (ø)
controller/sync_phase.go 100.00% <0.00%> (ø)
ui/src/app/applications/components/utils.tsx 49.83% <0.00%> (ø)
ui/src/app/shared/services/projects-service.ts 19.71% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 842a3d1...815ec40. Read the comment docs.

server/server.go Outdated
return &http.Server{
Addr: fmt.Sprintf("localhost:%d", port),
Addr: addr,
Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
target := "https://" + req.Host + req.URL.Path
Copy link
Collaborator

Choose a reason for hiding this comment

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

The server still redirects to root path. The changes have to be implemented in handler implementation. E.g.

		Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
			target := "https://" + req.Host
			if rootPath != "" {
				target += strings.TrimRight(strings.TrimLeft(rootPath, "/"), "/")
			}
			target += req.URL.Path
			if len(req.URL.RawQuery) > 0 {
				target += "?" + req.URL.RawQuery
			}
			http.Redirect(w, req, target, http.StatusTemporaryRedirect)
		}),

server/server.go Show resolved Hide resolved
1. when using https, redirect to the right URL.
2. when rootpath is set, handle healthz only.
1. when using https, redirect to the right URL.
2. when rootpath is set, handle healthz only.
Copy link
Collaborator

@alexmt alexmt left a comment

Choose a reason for hiding this comment

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

I've tried to verify https->http redirect behavior and noticed a bug.

http://localhost:8080/argocd1/applications was redirected to https://localhost:8080argocd1/applications . Can you take a look please?

server/server.go Outdated Show resolved Hide resolved
server/server.go Outdated
@@ -677,7 +677,7 @@ func newRedirectServer(port int, rootPath string) *http.Server {
return &http.Server{
Addr: addr,
Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
target := "https://" + req.Host
target := "https://" + req.Host + "/"
Copy link
Collaborator

@alexmt alexmt Apr 29, 2020

Choose a reason for hiding this comment

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

The req.URL.Path starts with /, so we might get double slash at https://github.com/argoproj/argo-cd/pull/3503/files/fd61815dfb544c9227f3814b9d44783a277b501e..b4cbc25337e748139cea282975dd6ed3fbe486d0#diff-91bbeda7eb98a7adc57b9e47e2cf5c2bR684.

Suggested change
target := "https://" + req.Host + "/"
target := "https://" + req.Host

Copy link
Collaborator

@alexmt alexmt left a comment

Choose a reason for hiding this comment

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

LGTM

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.

2 participants