From ea25bc8b4daa99390122c74448438b797408a31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20L=C3=B6he?= Date: Wed, 22 Nov 2023 22:08:06 +0100 Subject: [PATCH] docs: add dynamic replacements --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f5768df..7efb881 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,14 @@ app.use(serveStatic('public')); app.listen(3000); ``` +### Dynamic replacements + +You might also replace dynamically with access to all the content of [Request](https://expressjs.com/de/api.html#req) and [Response](https://expressjs.com/de/api.html#res): + +``` +stringReplace({ + '$host' => (req, res) => 'your host ' + req.hostname +}); ## Configuration @@ -61,4 +69,4 @@ app.use(stringReplace({ The default regex is `/^text\/|^application\/json$|^application\/xml$/`, which will match `text/*`, `application/json`, and `application/xml`. Any response with a Content-Type header that doesn't match the regex is ignored and passed-through without modification. -Also any response without a Content-Type header is ignored and passed-through without any modification. \ No newline at end of file +Also any response without a Content-Type header is ignored and passed-through without any modification.