Skip to content

Latest commit

 

History

History
40 lines (24 loc) · 1.65 KB

File metadata and controls

40 lines (24 loc) · 1.65 KB

HTML Rewrite Samples

This TypeScript and Rust implementations for a Spin app that does HTML rewriting using CSS selectors.

Both implementations accept the following configuration parameters:

Parameter Name Type Description
upstream_url string The desired upstream URL (request path will be appended before requests are sent to upstream)
use_kv_store boolean Indicating if key-value store should be used
ttl_in_minutes number Specify how long a upstream HTML document should remain in key-value store

Key-Value Store usage

If enabled, the app will cache the original HTML from upstream in key-value store and retrieve it from there for recurring requests to the same upstream url.

Rewrite behavior

The Spin app does rewriting only if the upstream server responds with an status code 200 and a content-type header containing text/html. Different upstream responses will be forwarded as-is to the callee.

Both sample implementations will replace contents of all h1 tags in the HTML with Hello Bot Protection this is Fermyon Wasm Functions

Running the Apps locally

Move to the application directory (either html-rewrite-rust or html-rewrite-ts) and execute the following commands:

cd html-rewrite-ts
spin up --build

This will start the HTML rewrite application on http://localhost:3000. With the default configuration, the app will send requests to https://www.fermyon.com (see upstream_url in spin.toml).

To request a re-written version of the index.html use the following curl command:

curl -iX GET http://localhost:3000/index.html