rewrite-link-middleware
v1.0.0
Published
Rewrite links in response
Downloads
2
Readme
rewrite-link-middleware
Returns Express middleware that serves a service worker that resets any previously set service worker configuration. Useful for development.
Example you development site on 127.0.0.1:3000
and have html
:
<!DOCTYPE html>
<html>
<head></head>
<body>
<a href="http://example.com/my/url">Link</a>
</body>
</html>
Using this middleware you will get:
<!DOCTYPE html>
<html>
<head></head>
<body>
<a href="//127.0.0.1:3000/my/url">Link</a>
</body>
</html>
Installation
npm i -D rewrite-link-middleware
API
const createRewriteLinkMiddleware = require("rewrite-link-middleware");
createRewriteLinkMiddleware(options)
Returns Express middleware that rewrite links in response.
Options
originalURL
Original URL hat you use in html document.
createRewriteLinkMiddleware({ originalURL: "http://example.com" });
createRewriteLinkMiddleware({
originalURL: ["http://example.com", "http://another-example.com"]
});
Other
See other options
Examples
Simple app:
const express = require("express");
const createRewriteLinkMiddleware = require("rewrite-link-middleware");
const app = express();
app.use(createRewriteLinkMiddleware({ originalURL: "http://example.com" }));
app.get("/", function(req, res) {
res.sendFile("index.html");
});
const createRewriteLinkMiddleware = require("rewrite-link-middleware");
module.exports = {
// ...
devServer: {
before(app, server) {
app.use(
createRewriteLinkMiddleware({ originalURL: "http://example.com" })
);
}
// ...
}
// ...
};