To run this POC:
npm installoryarnnpm i @types/react --save-devoryarn add --dev @types/reactnpm i @types/react-dom --save-devoryarn add --dev @types/react-domnpm startoryarn start
For dev run purposes install CORS extension in your browser to avoid CORS issues. For example Who CORS? and set Origin: to https://web-poc-astro.vercel.app/.
Test with reverse proxy, using Varnish running locally via Docker and mapped to the default backend localhost:3000, where the production version of the server (production build) is running.
-
Start the reverse proxy (Varnish) using Docker:
docker run \ -v /ABSOLUTE_PATH_TO/web-poc-tanstack-router-ssr/default.vcl:/etc/varnish/default.vcl:ro \ --tmpfs /var/lib/varnish/varnishd:exec \ --add-host=host.docker.internal:host-gateway \ -p 8080:80 \ varnish -
Generate the production build of the server using
npm run build:serverin./dist/server/entry-server.js -
Start the server (http://localhost:3000/) using
npm run serve -
Open the web browser and navigate to http://localhost:8080/
During interaction, you can filter out Doc in the console, enable Preserve log, and observe the results.
For the first request to a specific URL (cached based on host and params), the header should be X-Cache: MISS. Upon subsequent requests, it should be X-Cache: HIT, indicating the result is served from the cache. The same behavior should occur if the backend server (localhost:3000) is killed under Varnish, and the same request is retried.
You can also test this using curl:
curl -v 127.0.0.1:8080/events/2
curl --head -v 127.0.0.1:8080/events/2