Why does PathPrefixStrip work when PathPrefix won't?

社会主义新天地 提交于 2019-12-07 11:48:08

问题


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?


回答1:


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:

  1. The browser requests /environment/test/page
  2. Traefik translates this to a request to the container for /page
  3. The container is actually serving files on / so it answers with the page

When connecting via Traefik with the PathPrefix:

  1. The browser requests /environment/test/page
  2. Traefik translates this to a request to the container for /environment/test/page
  3. 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.



来源:https://stackoverflow.com/questions/50346047/why-does-pathprefixstrip-work-when-pathprefix-wont

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!