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

Prefix path router #3592

Open
wants to merge 131 commits into
base: main
Choose a base branch
from
Open

Prefix path router #3592

wants to merge 131 commits into from

Conversation

giuliaghisini
Copy link
Contributor

Enable to publish Volto site under a prefixPath, for example
www.mymainsite.com/prefixPath

@netlify
Copy link

netlify bot commented Aug 29, 2022

Deploy Preview for volto failed. Why did it fail? →

Name Link
🔨 Latest commit a38dda0
🔍 Latest deploy log https://app.netlify.com/sites/volto/deploys/6645ebd8e199fb0008479210

@cypress
Copy link

cypress bot commented Aug 29, 2022

Passing run #7234 ↗︎

0 14 0 0 Flakiness 0

Details:

refactor: prettify components
Project: Volto Commit: ef6216a98a
Status: Passed Duration: 02:07 💡
Started: Nov 28, 2023 11:05 AM Ended: Nov 28, 2023 11:07 AM

Review all test suite changes for PR #3592 ↗︎

@giuliaghisini giuliaghisini requested a review from mamico August 30, 2022 13:10
@pnicolli
Copy link
Contributor

pnicolli commented Sep 5, 2022

Link view now working, Image view still has issues with the download link which is not working (see this example)

@mamico mamico self-requested a review September 12, 2022 07:11
@sneridagh
Copy link
Member

sneridagh commented Sep 15, 2022

During the Volto Team meeting we agreed that we would have to put in place a whole round of Cypress tests pointing to a deployment using this. I can imagine that in the future will be quite easy to break the whole feature if one does not have in mind it.

I think that could be time consuming, but might not have much difficulty. What do you think?

@sneridagh sneridagh added this to the 16.x.x milestone Oct 1, 2022
@sneridagh
Copy link
Member

@mamico @giuliaghisini could you share the reverse proxy config you have on such deployments?

@sneridagh
Copy link
Member

We should add some documentation about how to setup such a deployment.
Also, I'll try to write a traefik config for testing it properly in CI.

@cekk
Copy link
Member

cekk commented Oct 3, 2022

@sneridagh our deployment config is a bit complicated because there are several urls and frontend names, and it's made in varnish and not in nginx/apache.

The conf itself for using this branch is easy. Here is an example for nginx:

upstream backend {
  server host.docker.internal:8080;
}
upstream frontend {
  server host.docker.internal:3000;
}

server {
  listen 80  default_server;
  server_name  localhost;

  location ~ /foo/\+\+api\+\+($|/) {
      rewrite ^/foo/\+\+api\+\+($|/.*) /VirtualHostBase/http/${server_name}/Plone/++api++/VirtualHostRoot/_vh_foo$1 break;
      proxy_pass http://backend;
  }


  location ~ /foo($|/) {
    
    # the standard nginx conf
    ...

    proxy_pass http://frontend;
  }
}

@tiberiuichim
Copy link
Contributor

@cekk One other thing is important to document, the prefix path /foo corresponds to the Plone root, not a /foo subfolder in Plone.

@cekk
Copy link
Member

cekk commented Oct 3, 2022

Yes, /foo points to the root of Plone site

@sneridagh
Copy link
Member

@cekk To make it work I had to launch Volto with:

RAZZLE_PREFIX_PATH=/foo RAZZLE_API_PATH=http://localhost/foo yarn start

I would have expect that given a RAZZLE_PREFIX_PATH, the other would have adjusted automatically (as seamless mode promises). I am doing something wrong? because given a look at the code, it seems it should, right?

@sneridagh
Copy link
Member

sneridagh commented Oct 4, 2022

@cekk Forget the question, I'm still asleep. 😅

@sneridagh
Copy link
Member

Added tentative tests: #3719 see comments.

@nileshgulia1
Copy link
Member

I would like to take this forward. Locally looks good. I will checkout this branch on one of our projects first and see if I find some issues.

State of this PR:

This PR is based on basename react-router prop which adds an initial entry to browser "history" stack and allows all links to be prefixed with basename by react-router. The static assets like images need to be explicitly prefixed. I amended an express-middleware which re-directs to app base path on initial load.

There is another approach in this PR, which uses a store enhancer middleware to prefix all the router paths(amending history accordingly) and modified flattenToAppUrl method.

What's left are the cypress tests #3719 which should also account for prefix path in the URLs. I will try to have a look into them.

I personally like the basename approach and let react-router handle the prefixes. However, we need to think about the non-router links and static assets. What do you think @sneridagh @davisagli @tiberiuichim @pnicolli ?

@nileshgulia1 nileshgulia1 mentioned this pull request Jan 21, 2023
9 tasks
@sneridagh sneridagh removed this from the 16.x.x milestone Jun 6, 2023
@wesleybl
Copy link
Member

wesleybl commented Jul 3, 2023

@giuliaghisini @nileshgulia1 @sneridagh any chance we have this feature in master?

@wesleybl
Copy link
Member

wesleybl commented Jul 4, 2023

I updated the branch and run:

RAZZLE_PREFIX_PATH=/my-prefix yarn start

Then I got the error:

ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
 - options has an unknown property 'publicPath'. These properties are valid:
   object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, magicHtml?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, server?, setupExitSignals?, setupMiddlewares?, static?, watchFiles?, webSocketServer? }
    at validate (/home/user/git/volto/node_modules/webpack-dev-server/node_modules/schema-utils/dist/validate.js:115:11)
    at new Server (/home/user/git/volto/node_modules/webpack-dev-server/lib/Server.js:231:5)
    at new razzleDevServer (/home/user/git/volto/node_modules/razzle/config/razzleDevServer.js:10:5)
    at /home/user/git/volto/node_modules/razzle/scripts/start.js:181:33
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

I'll take a look at it.

@tiberiuichim
Copy link
Contributor

@wesleybl it's due to the changes in razzle.config.js

@wesleybl
Copy link
Member

wesleybl commented Jul 4, 2023

@tiberiuichim I fixed this in: f011df6

@nileshgulia1
Copy link
Member

I'd love to talk to you as well in person

@sneridagh I sent you an email.

I'll be happy to join as well. Just ping me in discord.

@wesleybl
Copy link
Member

wesleybl commented Aug 6, 2024

@nileshgulia1 @sneridagh I documented in PLIP situations where it is necessary to manually prefix, when using react-router's basename. Is basically what is being done in this PR.

@teekuningas
Copy link

I wonder if this or similar could be included..

#3592 (comment)

Anyway, I hope this will merged soon! :- )

@wesleybl
Copy link
Member

I wonder if this or similar could be included..

#3592 (comment)

@teekuningas In our use case, we want cookies to be shared. But perhaps your suggestion could be a setting.

@teekuningas
Copy link

I wonder if this or similar could be included..
#3592 (comment)

@teekuningas In our use case, we want cookies to be shared. But perhaps your suggestion could be a setting.

Interesting, I wonder if that would work for us too.. anyway, a setting would be enough, yes.

@nileshgulia1
Copy link
Member

@wesleybl @teekuningas I talked to @sneridagh during PloneConf, and we agreed that we should rewrite the PR. We should extract the useful parts from it and possibly rewrite the PLIP to ensure it works with the current setup and can be easily upgraded when we move to Seven. What do you think? I agree to provide support maybe we should get in touch soon and target a sprint for it?

@wesleybl
Copy link
Member

I talked to @sneridagh during PloneConf, and we agreed that we should rewrite the PR

@nileshgulia1 That's exactly what I started doing with #6754. But instead of doing it all in one big PR, I think it's easier to split it up into multiple PRs.

development mode

addPrefixPath can receive URLs of the following type:

http://localhost:3000/++api++/@portrait/admin

Since in development mode, Plone should respond to URLs of this format,
it should not be prefixed.
When true, this prop forces the use of the 'a' tag in rendering. This is
for situations where the 'a' tag needs to be used and the prefix needs
to be added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs discussion
Development

Successfully merging this pull request may close these issues.

Prefix path setup