reverse-proxy-nodejs.md
January 11, 2025 · View on GitHub
Proxying Requests
Often third-party scripts are added to the page by appending a script tag.
However, because Partytown requests the scripts within a web worker using fetch(), then the script’s response requires the correct CORS headers.
Many third-party scripts already provide the correct CORS headers, but not all do. For services that do not add the correct headers, then a reverse proxy to another domain must be used in order to provide the CORS headers.
ref. From Docs
Example of a self-hosted reverse proxy on node.js to proxy such requests and add headers necessary for analytics ( or other functionality ) to work
Important : this should only be used for testing purposes and a tool for local testing, not a production solution.
Starting nodejs reverse-proxy server
- cd samples/nodejs-reverse-proxy
- npm install ( node v16+ )
- node server.js
- Next, the nodejs server will start, the default url is http://127.0.0.1:3000/proxy.
Configuration via M2 admin panel
- Stores -> Configuration -> Perspective -> Partytown
- In the Proxying Requests tab, enable proxying, specify the domains you want to proxy, and also specify the url for the proxy
Configuration Example: