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

feat: add support for baseUrl #2609

Merged
merged 12 commits into from
Jul 22, 2024
Merged

Conversation

aslafy-z
Copy link
Contributor

@aslafy-z aslafy-z commented Jun 25, 2024

Background

I want to host this microservice demo frontend on a subpath (X.X.X.X/online-boutique/). I made my reverse proxy rewrite the url by removing /online-boutique from the paths it sees. However, the frontend html pages uses absolute urls which cannot be solved with the reverse proxy.

Fixes

Change Summary

  • Introduce baseUrl from BASE_URL environment variable
  • Add baseUrl to default template variables
  • Prefix all absolute urls with baseUrl
  • Update handlers to use baseUrl
  • Update redirects to use baseUrl

Additional Notes

Image is available at docker.io/zadki3l/microservice-demo-frontend:v0.11.0-dev.4

Testing Procedure

  • Deploy app with BASE_URL=/online-boutique environment variable.

    Kustomize example
      kind: Kustomization
      namespace: online-boutique
      resources:
      - https://github.com/GoogleCloudPlatform/microservices-demo//kustomize/base?ref=6af73dcf7fe1ca653d95ae7a29e12faf8cf02964
      - namespace.yaml
      - ingress.yaml
      components:
      - https://github.com/GoogleCloudPlatform/microservices-demo//kustomize/components/non-public-frontend?ref=6af73dcf7fe1ca653d95ae7a29e12faf8cf02964
      - https://github.com/GoogleCloudPlatform/microservices-demo//kustomize/components/without-loadgenerator?ref=6af73dcf7fe1ca653d95ae7a29e12faf8cf02964
      images:
       - name: gcr.io/google-samples/microservices-demo/frontend
         newName: docker.io/zadki3l/microservice-demo-frontend
         newTag: v0.11.0
      patches:
      - patch: |-
          - op: add
            path: "/spec/template/spec/containers/0/env/-"
            value:
              name: BASE_URL
              value: "/online-boutique"
        target:
          kind: Deployment
          name: frontend
  • Deploy an ingress with /online-boutique prefix.

  • Validate that everything shows correctly

Related PRs or Issues

@aslafy-z aslafy-z marked this pull request as ready for review June 25, 2024 12:03
@aslafy-z aslafy-z requested review from yoshi-approver and a team as code owners June 25, 2024 12:03
Copy link
Collaborator

@NimJay NimJay left a comment

Choose a reason for hiding this comment

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

Thanks for this feature.

It looks like the "You May Also Like" section of each product page is broken in the staging URL:
Screenshot 2024-06-27 at 2 48 12 PM

Do you know if it might be due to a change in the .html templates?

@aslafy-z
Copy link
Contributor Author

aslafy-z commented Jul 2, 2024

@NimJay I don't think so, the same changes were done on the product listing page without issue: https://github.com/GoogleCloudPlatform/microservices-demo/pull/2609/files#diff-486e203835857587dcd0bd356e4778094d7514a853fcfb8d83b6c0163b471eaeL48-L49.

Edit: My bad, I confirm recommendations are broken. I will look for a solution.

@aslafy-z aslafy-z requested a review from NimJay July 2, 2024 16:12
@aslafy-z
Copy link
Contributor Author

aslafy-z commented Jul 2, 2024

I updated the code to fix Ad and Recommendation templates. I had to pass them the global context. I'm not a fan of that solution, however, it works well.
I pushed an updated image at docker.io/zadki3l/microservice-demo-frontend:v0.11.0-dev.4.

@NimJay NimJay merged commit 7ac4a1e into GoogleCloudPlatform:main Jul 22, 2024
6 checks passed
@aslafy-z aslafy-z deleted the patch-2 branch July 22, 2024 15:11
@aslafy-z aslafy-z restored the patch-2 branch July 22, 2024 15:12
@NimJay NimJay mentioned this pull request Jul 24, 2024
5 tasks
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