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>
npm i -D rewrite-link-middleware
const createRewriteLinkMiddleware = require("rewrite-link-middleware");
Returns Express middleware that rewrite links in response.
Original URL hat you use in html document.
createRewriteLinkMiddleware({ originalURL: "http://example.com" });
createRewriteLinkMiddleware({
originalURL: ["http://example.com", "http://another-example.com"]
});
See other options
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" })
);
}
// ...
}
// ...
};