node-iframe
create iframes to bypass security issues on your server with node.js can also be used on the client
Installation
npm install node-iframe
or yarn add node-iframe
How to use
On your server if using with express
const createIframe = require("node-iframe");
app.use(createIframe);
app.get("/iframe", (req, res) =>
res.createIframe({
url: req.query.url,
baseHref: req.query.baseHref,
config: JSON.parse(req.query.config),
})
);
On the client use directly in your iframe if your api is on the same server set the url below like this or if your using a framework like gatsby, nextjs, etc or non-express apps
<iframe src="/iframe/?url=https://www.etsy.com" />
You can even fetch the iframe directly by importing fetchFrame on the client or server.
const {
fetchFrame,
configureResourceControl,
configureCacheControl,
configureTemplates,
} = require("node-iframe");
configureResourceControl({
inline: { script: true, link: false },
cors: { script: true },
});
configureCacheControl({ stdTTL: 0, checkperiod: 600, disabled: false });
configureTemplates("<div>No Fish found</div>", 1);
async function fetchIframe() {
return await fetchFrame({ url: "https://www.etsy.com" });
}
Example
License
MIT