Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a GatsbyJS static site built with --prefix-paths . The pathPrefix is set to /environment/test in gatsby-config.js . It is deployed to a docker swarm running Traefik.

Adding the following label to the service makes everything run ok: traefik.frontend.rule=PathPrefixStrip:/environment/test

I can then browse to /environment/test and click around in my GatsbyJs site.

However I find it strange since the backend is build with the path prefix.

Adding the following label does not work: traefik.frontend.rule=PathPrefix:/environment/test

Shouldn't it work with PathPrefix instead of PathPrefixStrip ?

The pathPrefix configuration in GatsbyJS means that every link of your website will be prepended with /environment/test (see documentation ), but this does not mean that on the container running the website, the page is actually hosted on this path. In your situation, it seems it is not the case.

This means that when connecting via Traefik with the PathPrefixStrip , when in your browser you click on a link:

  • The browser requests /environment/test/page
  • Traefik translates this to a request to the container for /page
  • The container is actually serving files on / so it answers with the page
  • When connecting via Traefik with the PathPrefix :

  • The browser requests /environment/test/page
  • Traefik translates this to a request to the container for /environment/test/page
  • The container is actually serving files on / so it doesn't find the page.
  • Hence, you are confusing the pathPrefix setting of a website with the path from which the very same website is served.

    The alternative to the current situation would thus be to serve the website under /environment/test/ and use PathPrefix with traefik.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question . Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers .