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 116 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
3e22a58
added prefixPath for site
giuliaghisini May 12, 2022
a6cf32e
handle prefixPath in api requests
giuliaghisini May 13, 2022
a523fa7
added Image component to handle prefixPath in images
giuliaghisini May 13, 2022
30d2638
fixed prefix path in page head
giuliaghisini May 13, 2022
0be7e30
handle prefixPath in chunkExtractor
giuliaghisini May 13, 2022
ab146ac
fixed publickPath in ChunkExtractor with prefixPath
giuliaghisini May 13, 2022
cb21196
added namespace to chunkextractor
giuliaghisini May 13, 2022
4c35003
fix static paths in razzle
cekk May 13, 2022
67452b7
handle static resources with prefix path
giuliaghisini May 16, 2022
c485e5f
fix: fix empty values
giuliaghisini May 20, 2022
9505e56
fix: fix flattenHTMLtoAppUrl to handle prefixPath
giuliaghisini May 27, 2022
f2f908e
feat: added addPrefixPath util to handle static resources
giuliaghisini Aug 11, 2022
c284ec5
Update APIResourceWithAuth.js
giuliaghisini Aug 30, 2022
97f3f9c
Update Api.js
giuliaghisini Aug 30, 2022
f37a938
fix: fix linter
giuliaghisini Aug 31, 2022
76f0f33
fix: image and file views
pnicolli Sep 2, 2022
ed28182
fix: image and file views
pnicolli Sep 2, 2022
57537bb
fix: back to using simple <a> tag for ImageView
pnicolli Sep 5, 2022
4a6f184
readded tests inadvertently removed
mamico Sep 10, 2022
dfdd13f
fix tests
mamico Sep 11, 2022
e38bccc
fix tests
mamico Sep 11, 2022
cf7d2ae
fix(warning): StyleMenu dropdown item to use data-attr instead of cus…
nileshgulia1 Nov 9, 2022
3be3238
add prefix-path express-middleware
nileshgulia1 Dec 8, 2022
1ceb872
Put prefixPath in config.devServer.devMiddleware.publicPath
wesleybl Jul 4, 2023
d6f8bab
Add cypress to prefix path router (#3719)
sneridagh Jul 12, 2023
7f435b0
Avoid /my-prefix from being redirected to /my-prefix/
wesleybl Jul 12, 2023
aa7ef2b
Merge branch 'master' into prefix_path_router
nileshgulia1 Jul 18, 2023
30a9799
Merge branch 'main' into prefix_path_router
nileshgulia1 Nov 17, 2023
63c7858
Merge branch 'main' into prefix_path_router
nileshgulia1 Nov 17, 2023
035bc59
Merge branch 'main' into prefix_path_router
claudiaifrim Nov 17, 2023
392bdfd
Merge branch 'main' into prefix_path_router
nileshgulia1 Nov 20, 2023
9af9eb8
tests: update snapshots
nileshgulia1 Nov 20, 2023
e201fc3
fix(tests): remove duplicate testing-library import
nileshgulia1 Nov 20, 2023
3089740
tests: fix assertion on img src
nileshgulia1 Nov 20, 2023
7037193
tests: more fixes
nileshgulia1 Nov 20, 2023
1b4baa6
tests: intercept prefix calls
nileshgulia1 Nov 21, 2023
cc13733
tests: bring back multilingual cypress suite
nileshgulia1 Nov 22, 2023
88d8ed4
Merge branch 'main' into prefix_path_router
nileshgulia1 Nov 22, 2023
bbf84cb
fix: remove unneeded code
nileshgulia1 Nov 25, 2023
3ad97df
fix: use asyncPropExtenders for /controlpanel route when prefixed
nileshgulia1 Nov 26, 2023
6b3e876
Merge branch 'main' into prefix_path_router
nileshgulia1 Nov 27, 2023
b964d97
fix: test-setup config
nileshgulia1 Nov 27, 2023
b8d8413
fix(test): controlpanels.test.jsx
nileshgulia1 Nov 27, 2023
40e5379
Merge branch 'main' into prefix_path_router
nileshgulia1 Nov 28, 2023
db1fe08
refactor: use `addPrefixPath` helper in Image src
nileshgulia1 Nov 28, 2023
ef6216a
refactor: prettify components
nileshgulia1 Nov 28, 2023
21162d3
Merge branch 'main' into prefix_path_router
nileshgulia1 Dec 18, 2023
14de201
fix(CI): use pnpm
nileshgulia1 Dec 18, 2023
e8b3859
fix(CI): run cypress in packages/volto, update changelog
nileshgulia1 Dec 19, 2023
04dc8aa
fix: update prefix-tests
nileshgulia1 Dec 19, 2023
ecd601d
refactor: shift acceptance tests in packages/volto MAKEFILE
nileshgulia1 Dec 19, 2023
0b5bff7
ref:point to internal makefile tests
nileshgulia1 Dec 19, 2023
260cfcd
update acceptance.yml
nileshgulia1 Dec 19, 2023
f3dd2b5
fix: force yarn to vanish completely
nileshgulia1 Dec 19, 2023
1c676ff
update makefile
nileshgulia1 Dec 19, 2023
cfb5a73
fix: move changelog to correct folder
nileshgulia1 Dec 19, 2023
000f503
delete dangling one
nileshgulia1 Dec 19, 2023
76008a6
chore: amend volto-slate changelog
nileshgulia1 Dec 19, 2023
39c1e4a
Merge branch 'main' into prefix_path_router
claudiaifrim Jan 19, 2024
22749f9
Merge branch 'main' into prefix_path_router
claudiaifrim Jan 25, 2024
1b78ad5
Merge branch 'main' into prefix_path_router
nileshgulia1 Jan 29, 2024
fc56c8e
feat: add multilingual prefixed tests
nileshgulia1 Jan 29, 2024
73a3dab
Merge branch 'main' into prefix_path_router
nileshgulia1 Jan 31, 2024
ca6004e
Merge branch 'main' into prefix_path_router
nileshgulia1 Feb 12, 2024
3f3e81f
fix workflow multilingualprefix
nileshgulia1 Feb 12, 2024
ea9c14b
Merge branch 'main' into prefix_path_router
nileshgulia1 Feb 13, 2024
caae9ab
Merge branch 'main' into prefix_path_router
nileshgulia1 Feb 14, 2024
a06a91c
Merge branch 'main' into prefix_path_router
claudiaifrim Feb 22, 2024
735090c
Merge branch 'main' into prefix_path_router
wesleybl Feb 27, 2024
aa0c72b
Merge remote-tracking branch 'origin/main' into prefix_path_router
wesleybl Mar 6, 2024
3938b21
Acceptance tests of prefixed site in Node 20.x
wesleybl Mar 6, 2024
b07f431
Update github actions versions
wesleybl Mar 6, 2024
3a10d4a
Force install Cypress
wesleybl Mar 6, 2024
562e01e
Restore condition to install Cypress
wesleybl Mar 6, 2024
c50341b
Fix cache key
wesleybl Mar 7, 2024
61d96d2
Use addPrefixPath in Logo component
wesleybl Mar 7, 2024
c793816
Use addPrefixPath in image scales
wesleybl Mar 8, 2024
48554df
Merge branch 'main' into prefix_path_router
wesleybl Mar 8, 2024
294a090
Merge branch 'main' into prefix_path_router
nileshgulia1 Mar 11, 2024
ad3a147
Merge branch 'main' into prefix_path_router
wesleybl Mar 13, 2024
8d8edf3
Merge branch 'main' into prefix_path_router
wesleybl Mar 14, 2024
9a6b25f
Remove use asyncPropExtenders for /controlpanel route when prefixed
wesleybl Mar 14, 2024
149c899
Add routes with prefix path
wesleybl Mar 15, 2024
e32637b
Test core basic with prefixed site
wesleybl Mar 14, 2024
5eddf39
Test core content with prefixed site
wesleybl Mar 15, 2024
8cf3b05
Test core control panels with prefixed site
wesleybl Mar 15, 2024
5ce2e94
Test core blocks with prefixed site
wesleybl Mar 15, 2024
a59a704
Add prefix to the URL of Image Gallery images
wesleybl Mar 18, 2024
2944946
Pass the prefixPath environment variable to the test-acceptance-prefixed
wesleybl Mar 18, 2024
235e4c5
Test core blocks listing with prefixed site
wesleybl Mar 15, 2024
38e428c
Test core volto slate with prefixed site
wesleybl Mar 18, 2024
1e2620e
Merge branch 'main' into prefix_path_router
wesleybl Mar 18, 2024
f3a51a4
Merge branch 'main' into prefix_path_router
nileshgulia1 May 13, 2024
433ad1c
fix: use prefix in flattenToAppUrl, keep assets intact in dev
nileshgulia1 May 16, 2024
dd553b8
remove: addprefixPath helper
nileshgulia1 May 16, 2024
d66b0ac
fix: client and server warnings
nileshgulia1 May 16, 2024
a38dda0
Merge branch 'main' into prefix_path_router
nileshgulia1 May 16, 2024
0afb5c7
Merge branch 'main' into prefix_path_router
sneridagh Jun 7, 2024
b220146
Merge remote-tracking branch 'origin/main' into prefix_path_router
wesleybl Jul 8, 2024
699dfb1
Update pnpm-lock.yaml with main
wesleybl Jul 8, 2024
e8b69cf
Rename Makefile targets
wesleybl Jul 10, 2024
d1263ee
Merge branch 'main' into prefix_path_router
nileshgulia1 Jul 11, 2024
c2ae5a4
Does not add prefix in the flattenToAppURL function
wesleybl Jul 12, 2024
223cf17
Create function addPrefixPath
wesleybl Jul 15, 2024
0d357e1
Uses addPrefixPath where it is not possible to use the Link and
wesleybl Jul 15, 2024
453bdbc
Merge branch 'main' into prefix_path_router
wesleybl Jul 24, 2024
7efbd7f
Merge branch 'main' into prefix_path_router
wesleybl Jul 26, 2024
9e4712e
Merge branch 'main' into prefix_path_router
wesleybl Jul 30, 2024
06f3e1f
Allows use of RAZZLE PREFIX PATH variable in development mode
wesleybl Jul 30, 2024
e6ea8aa
Merge branch 'main' into prefix_path_router
wesleybl Oct 29, 2024
2b59a49
Uses actions/upload-artifact v4
wesleybl Oct 29, 2024
3856b7c
Updates configuration of prefixed acceptance tests
wesleybl Oct 29, 2024
5e90e60
Use `docker compose` in deployment-prefixed-acceptance-web-server-start
wesleybl Oct 29, 2024
e8889fe
Fixes prefixed workingcopy tests
wesleybl Oct 30, 2024
ccc0b0e
Allows use of RAZZLE_PREFIX_PATH variable in development mode
wesleybl Nov 4, 2024
01148eb
Does not avoid redirect /prefix -> prefix/
wesleybl Nov 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
409 changes: 409 additions & 0 deletions .github/workflows/acceptance.yml

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,42 @@ multilingual-ci-acceptance-test: ## Run Cypress tests in headless mode for CI fo
multilingual-ci-acceptance-test-run-all: ## With a single command, run the backend, frontend, and the Cypress tests in headless mode for CI for multilingual tests
$(MAKE) -C "./packages/volto/" multilingual-ci-acceptance-test-run-all

######### Prefixed Core Acceptance tests

.PHONY: prefixed-acceptance-frontend-prod-start
prefixed-acceptance-frontend-prod-start: ## Start the prefixed Core Acceptance Frontend Fixture
$(MAKE) -C "./packages/volto/" prefixed-acceptance-frontend-prod-start

.PHONY: prefixed-ci-acceptance-test-run-all
prefixed-ci-acceptance-test-run-all: ## Runs prefixed Core Full Acceptance Testing in headless mode
$(MAKE) -C "./packages/volto/" prefixed-ci-acceptance-test-run-all

.PHONY: prefixed-acceptance-test
prefixed-acceptance-test: ## Start Prefixed Cypress Acceptance Tests
$(MAKE) -C "./packages/volto/" prefixed-acceptance-test

.PHONY: deployment-prefixed-acceptance-web-server-start
deployment-prefixed-acceptance-web-server-start: ## Start the prefixed webserver
$(MAKE) -C "./packages/volto/" deployment-prefixed-acceptance-web-server-start

######### Prefixed Working Copy Acceptance tests

.PHONY: prefixed-working-copy-acceptance-frontend-prod-start
prefixed-working-copy-acceptance-frontend-prod-start: ## Start acceptance frontend in production mode for prefixed working copy tests
$(MAKE) -C "./packages/volto/" prefixed-working-copy-acceptance-frontend-prod-start

.PHONY: prefixed-working-copy-acceptance-test
prefixed-working-copy-acceptance-test: ## Start Cypress in interactive mode for prefixed working copy tests
$(MAKE) -C "./packages/volto/" prefixed-working-copy-acceptance-test

.PHONY: prefixed-prefixed-working-copy-ci-acceptance-test
prefixed-working-copy-ci-acceptance-test: ## Run Cypress tests in headless mode for CI for prefixed working copy tests
$(MAKE) -C "./packages/volto/" prefixed-working-copy-ci-acceptance-test

.PHONY: prefixed-working-copy-ci-acceptance-test-run-all
prefixed-working-copy-ci-acceptance-test-run-all: ## With a single command, run the backend, frontend, and the Cypress tests in headless mode for CI for prefixed working copy tests
$(MAKE) -C "./packages/volto/" prefixed-working-copy-ci-acceptance-test-run-all

######### Deployment Multilingual Acceptance tests

.PHONY: deployment-multilingual-acceptance-backend-start
Expand Down
1 change: 1 addition & 0 deletions docs/source/deploying/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ seamless-mode
apache
sentry
performance
prefixed-root
```
58 changes: 58 additions & 0 deletions docs/source/deploying/prefixed-root.md
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that this page needs to have better narrative structure, such as the following:

  • Introduction that states the essential and basic requirements for a deployment, regardless of root or non-root. This might already exist somewhere in the Deploying section. Side note: that entire section needs to be cleaned up, and I think the index page should have this introduction as its introduction, so we can easily refer to it. We can also use an include to avoid copy-paste drift.
  • Clarify what these requirements do and why they are necessary.
  • Then add to the basic requirements those things that are required for a non-root deployment.
  • Again, clarify what these requirements do and why they are necessary.
  • Finally show examples of implementation details, whether it is Apache, nginx, or whatever. It is OK to have multiple examples. In fact I would use Sphinx Design with a tabbed code example interface.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
myst:
html_meta:
"description": "Prefixed (non-root) deployment for Volto"
"property=og:description": "Prefixed (non-root) deployment for Volto"
"property=og:title": "Prefixed (non-root) deployment"
"keywords": "Volto, deployment"
---

# Prefixed (non-root) deployment

If you're integrating a Volto website within another existing website, you may need to run Volto on a virtual path inside that website instead of the root path.

The first step is to set an environment variable `RAZZLE_PREFIX_PATH` to the prefixed path of your Volto.
For example, if you want Volto's root to be hosted at `http://example.com/my-prefix`, you need to start Volto with:

```shell
RAZZLE_PREFIX_PATH=/my-prefix yarn start
```

If you need to debug and understand how the requests are rewritten by the Volto SSR, you can add the following environment variables to the Volto start line:


```shell
DEBUG_HPM=true DEBUG=superagent RAZZLE_PREFIX_PATH=/my-prefix yarn start
```

The prefix location will be used regardless of how you start Volto, whether in development or production mode.
When developing, though, if your backend is something other then `http://localhost:8080`, you'll need to provide your own solution for how to handle things.
Copy link
Member

Choose a reason for hiding this comment

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

So in development I don't have to set it up and act as I'm in the root then?


For a production setup, when hosting Volto behind a proxy HTTP server, you can configure your rewrite rules to something like the following, in this case for Apache.

```apache
Copy link
Member

Choose a reason for hiding this comment

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

The recommended deployment setup is using Docker. I know that the documentation about this is in a sorry state, but we cannot add more confusion about this by dropping an Apache config here. I don't have a good solution for this one :(

In the upcoming sprints we should work on documenting properly the deployment story.

/cc @ericof @davisagli @stevepiercy @fredvd

Copy link
Member

Choose a reason for hiding this comment

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

@sneridagh would it be an idea to use an example with nginx, since docker uses nginx?

RewriteRule ^/level-1/\+\+api\+\+(.*) http://plone:8080/VirtualHostBase/http/example.com:80/Plone/VirtualHostRoot/_vh_level-1$1 [P,L]
RewriteRule ^/level-1(.*) http://volto:3000/level-1$1 [P,L]
```

In case you have a deeper prefix path (for example, `/level1/level2`), you can do the following.
Notice the multiple `_vh_` segments in the rewrite rule.

```apache
RewriteRule ^/level-1/level-2/\+\+api\+\+(.*) http://plone:8080/VirtualHostBase/http/example.com:80/Plone/VirtualHostRoot/_vh_level-1/_vh_level-2$1 [P,L]
RewriteRule ^/level-1/level-2(.*) http://volto:3000/level-1/level-2$1 [P,L]
```

And start Volto with the following.

```shell
RAZZLE_PREFIX_PATH=/level1/level2 RAZZLE_API_PATH=http://example.com/level1/level2 yarn start
```

Note, as you'll be integrating Volto with an existing website, you need to configure `config.settings.externalRoutes` so that the router knows which routes it should consider internal.
Copy link
Member

Choose a reason for hiding this comment

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

Need more elaboration and reasoning why this is necessary.


Finally, because `RAZZLE_PREFIX_PATH` is also used to configure the location of the static resources in webpack, when you build the static resources bundle, you must use a command such as the following.

```shell
RAZZLE_PREFIX_PATH=/level1/level2 yarn build
```
1 change: 1 addition & 0 deletions packages/volto-slate/news/4290.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
added support for prefixPath. @giuliaghisini @cekk @pnicolli @mamico @nileshgulia1 @wesleybl
3 changes: 2 additions & 1 deletion packages/volto-slate/src/editor/plugins/Image/render.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { useSelected, useFocused } from 'slate-react';
import { Image } from '@plone/volto/components';

export const ImageElement = (props) => {
const { attributes, children, element } = props;
Expand All @@ -16,7 +17,7 @@ export const ImageElement = (props) => {
return (
<span {...attributes} style={{ display: 'inline-block' }}>
{children}
<img alt="" src={element.url} style={style} />
<Image alt="" src={element.url} style={style} />
</span>
);
};
45 changes: 45 additions & 0 deletions packages/volto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,51 @@ working-copy-ci-acceptance-test: ## Run Cypress tests in headless mode for CI fo
working-copy-ci-acceptance-test-run-all: ## With a single command, run the backend, frontend, and the Cypress tests in headless mode for CI for working copy tests
$(NODEBIN)/start-test "make working-copy-acceptance-backend-start" http-get://127.0.0.1:55001/plone "make working-copy-acceptance-frontend-prod-start" http://127.0.0.1:3000 "make working-copy-ci-acceptance-test"

######### Prefixed Core Acceptance tests

.PHONY: prefixed-acceptance-frontend-prod-start
prefixed-acceptance-frontend-prod-start: build-deps ## Start the prefixed Core Acceptance Frontend Fixture
RAZZLE_PREFIX_PATH=/foo RAZZLE_API_PATH=http://localhost/foo pnpm build && pnpm start:prod

.PHONY: prefixed-ci-acceptance-test-run-all
prefixed-ci-acceptance-test-run-all: ## Runs prefixed Core Full Acceptance Testing in headless mode
$(NODEBIN)/start-test "make ci-acceptance-backend-start" http-get://localhost:55001/plone "make prefixed-acceptance-frontend-prod-start" http://localhost:3000 "make ci-acceptance-test"

.PHONY: prefixed-acceptance-test
prefixed-acceptance-test: ## Start Prefixed Cypress Acceptance Tests
NODE_ENV=production CYPRESS_API=plone $(NODEBIN)/cypress open --config baseUrl='http://localhost/foo' --env prefixPath="/foo"

.PHONY: deployment-prefixed-acceptance-web-server-start
deployment-prefixed-acceptance-web-server-start: ## Start the prefixed webserver
cd cypress/docker && docker compose -f prefixed.yml up

######### Prefixed Working Copy Acceptance tests

.PHONY: prefixed-working-copy-acceptance-frontend-prod-start
prefixed-working-copy-acceptance-frontend-prod-start: build-deps ## Start acceptance frontend in production mode for prefixed working copy tests
RAZZLE_PREFIX_PATH=/foo ADDONS=@plone/volto-coresandbox:workingCopyFixture RAZZLE_API_PATH=http://localhost/foo pnpm build && pnpm start:prod

.PHONY: prefixed-working-copy-acceptance-test
prefixed-working-copy-acceptance-test: ## Start Cypress in interactive mode for prefixed working copy tests
NODE_ENV=production CYPRESS_API=plone $(NODEBIN)/cypress open --config specPattern='cypress/tests/workingCopy/**/*.{js,jsx,ts,tsx}' --config baseUrl='http://localhost/foo' --env prefixPath='/foo'

.PHONY: prefixed-working-copy-ci-acceptance-test
prefixed-working-copy-ci-acceptance-test: ## Run Cypress tests in headless mode for CI for prefixed working copy tests
NODE_ENV=production CYPRESS_API=plone $(NODEBIN)/cypress run --config specPattern='cypress/tests/workingCopy/**/*.{js,jsx,ts,tsx}' --config baseUrl='http://localhost/foo' --env prefixPath='/foo'

.PHONY: prefixed-working-copy-ci-acceptance-test-run-all
prefixed-working-copy-ci-acceptance-test-run-all: ## With a single command, run the backend, frontend, and the Cypress tests in headless mode for CI for prefixed working copy tests
$(NODEBIN)/start-test \
"make working-copy-acceptance-backend-start & make prefixed-working-copy-acceptance-frontend-prod-start & make deployment-prefixed-acceptance-web-server-start" \
http://localhost/foo \
"make prefixed-working-copy-ci-acceptance-test"

######### Prefixed Multilingual Acceptance tests

.PHONY: prefixed-multilingual-acceptance-frontend-prod-start
prefixed-multilingual-acceptance-frontend-prod-start: build-deps ## Start the prefixed Core Acceptance Frontend Fixture
ADDONS=@plone/volto-coresandbox:multilingualFixture RAZZLE_PREFIX_PATH=/foo RAZZLE_API_PATH=http://localhost/foo pnpm build && pnpm start:prod

######### Guillotina Acceptance tests

.PHONY: guillotina-acceptance-backend-start
Expand Down
27 changes: 27 additions & 0 deletions packages/volto/cypress/docker/prefixed-rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
http:
routers:
frontend:
rule: "Host(`localhost`) && PathPrefix(`/foo`)"
service: frontend
backend:
rule: "Host(`localhost`) && PathPrefix(`/foo/++api++`)"
service: backend
middlewares:
- backend

middlewares:
backend:
replacePathRegex:
regex: "^/foo/\\+\\+api\\+\\+($|/.*)"
replacement: "/VirtualHostBase/http/localhost/plone/++api++/VirtualHostRoot/_vh_foo$1"

services:
frontend:
loadBalancer:
servers:
- url: "http://host.docker.internal:3000"
backend:
loadBalancer:
servers:
- url: "http://host.docker.internal:55001"

24 changes: 24 additions & 0 deletions packages/volto/cypress/docker/prefixed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "3.7"

services:

proxy:
image: traefik:v2.8
command:
- "--api.insecure=true"
- "--providers.docker=true"
# - "--providers.docker.exposedbydefault=false"
- "--providers.file=true"
- "--providers.file.filename=/etc/traefik/rules.yml"
- "--entrypoints.web.address=:80"
- "--api.insecure=true"
# - "--accesslog=true"
# - "--log.level=DEBUG"
ports:
- 80:80
- "8888:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./prefixed-rules.yml:/etc/traefik/rules.yml
extra_hosts:
- host.docker.internal:host-gateway
33 changes: 33 additions & 0 deletions packages/volto/cypress/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,36 @@ export function getIfExists(
}
});
}

export function getTextNode(el, match) {
const walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false);
if (!match) {
return walk.nextNode();
}

const nodes = [];
let node;
while ((node = walk.nextNode())) {
if (node.wholeText.includes(match)) {
return node;
}
}
}

export function setBaseAndExtent(...args) {
const document = args[0].ownerDocument;
document.getSelection().removeAllRanges();
document.getSelection().setBaseAndExtent(...args);
}

export function createHtmlPasteEvent(htmlContent) {
return Object.assign(
new Event('paste', { bubbles: true, cancelable: true }),
{
clipboardData: {
getData: () => htmlContent,
types: ['text/html'],
},
},
);
}
47 changes: 14 additions & 33 deletions packages/volto/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {
getIfExists,
getTextNode,
setBaseAndExtent,
createHtmlPasteEvent,
} from '../helpers';
/* eslint-disable no-console */
import '@testing-library/cypress/add-commands';
import { getIfExists } from '../helpers';
import { ploneAuth } from './constants';

const HOSTNAME = Cypress.env('BACKEND_HOST') || '127.0.0.1';
Expand Down Expand Up @@ -841,38 +846,14 @@ Cypress.Commands.add('clickSlateButton', (button, timeout = 1000) => {
}).click({ force: true }); // force click is needed to ensure the button in visible in view.
});

// Helper functions
Copy link
Member

Choose a reason for hiding this comment

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

+1 I started this already in a recent PR. A merge might be needed.

function getTextNode(el, match) {
const walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false);
if (!match) {
return walk.nextNode();
}

let node;
while ((node = walk.nextNode())) {
if (node.wholeText.includes(match)) {
return node;
}
}
}

function setBaseAndExtent(...args) {
const document = args[0].ownerDocument;
document.getSelection().removeAllRanges();
document.getSelection().setBaseAndExtent(...args);
}

function createHtmlPasteEvent(htmlContent) {
return Object.assign(
new Event('paste', { bubbles: true, cancelable: true }),
{
clipboardData: {
getData: () => htmlContent,
types: ['text/html'],
},
},
);
}
/* add prefixPath from Cypress.env to supplied path
* designed for CI only
* for local, add prefixPath to Cypress.env
*/
Cypress.Commands.add('addBaseUrl', (url) => {
const prefixPath = Cypress.env('prefixPath');
return prefixPath ? prefixPath + url : url;
});

Cypress.Commands.add('addNewBlock', (blockName, createNewSlate = false) => {
let block;
Expand Down
8 changes: 5 additions & 3 deletions packages/volto/cypress/tests/core/basic/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
describe('actions Tests', () => {
let prefixPath;
beforeEach(() => {
cy.autologin();
cy.createContent({
Expand All @@ -8,6 +9,7 @@ describe('actions Tests', () => {
allow_discussion: true,
});
cy.visit('/contents');
prefixPath = Cypress.env('prefixPath') || '';
});
it('copy', function () {
cy.get('tr[aria-label="/my-page-1"]').within(() => {
Expand All @@ -20,7 +22,7 @@ describe('actions Tests', () => {
cy.get('a[class="icon-align-name"]').should(
'have.attr',
'href',
'/copy_of_my-page-1/contents',
`${prefixPath}/copy_of_my-page-1/contents`,
);
});
});
Expand All @@ -44,7 +46,7 @@ describe('actions Tests', () => {
cy.get('a[class="icon-align-name"]').should(
'have.attr',
'href',
'/my-page-1/contents',
`${prefixPath}/my-page-1/contents`,
Copy link
Member

Choose a reason for hiding this comment

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

Can't we do it more elegant by invoking the baseUrl from Cypress config?

Copy link
Member

Choose a reason for hiding this comment

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

@sneridagh yes would be. And it would be less code to change. When I have time I will change this.

Copy link
Member

Choose a reason for hiding this comment

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

@sneridagh I started looking into this but that won't be possible. baseURL contains the URL with the domain. For example:

http://localhost/foo

But links in HTML are relative. For example:

/foo/my-document

);
});
});
Expand All @@ -62,7 +64,7 @@ describe('actions Tests', () => {
cy.get('a[class="icon-align-name"]').should(
'have.attr',
'href',
'/my-page-rename/contents',
`${prefixPath}/my-page-rename/contents`,
);
});
});
Expand Down
Loading
Loading