Code Monkey home page Code Monkey logo

node-iframe's Introduction

node-iframe

create iframes to bypass security issues on your server with node.js can also be used in a browser

Installation

npm install node-iframe

How to use

as express middleware

import createIframe from "node-iframe";

app.use(createIframe);

app.get("/iframe", (req, res) => {
  res.createIframe({
    url: req.query.url,
    baseHref: req.query.baseHref, // optional: determine how to control link redirects,
    config: { cors: { script: true } }, // optional: determine element cors or inlining #shape src/iframe.ts#L34
  });
});

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. Set safeMode=true in conjunction with inline scripts to add error handling.

import { fetchFrame } from "node-iframe";

async function fetchIframe() {
  return await fetchFrame({ url: "https://www.etsy.com", safeMode: false });
}

Configure how to handle resources for all request

const { configureResourceControl, configureTemplates } = require("node-iframe");

// optional: configure if elements should be inlined, cors, etc, this combines with the `config` param
configureResourceControl({
  inline: { script: true, link: false },
  cors: { script: true },
});
// optional: configure error-pages - check src/templates for more info
// 0: error, 1: not-found, 2: all templates - check src/templates/config for options
configureTemplates("<div>No Fish found</div>", 1);

Example

License

MIT

node-iframe's People

Contributors

j-mendez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-iframe's Issues

Error on self-signed SSL certificates

Hi,

I would just like to ask something,
I tried using this library with an https site that I created (it's a self-signed SSL certificate),

and it gives me this error on the server:

FetchError: request to https://192.168.100.113:8231/login failed, reason: unable to verify the first certificate
at ClientRequest. (\node_modules\node-fetch\lib\index.js:1461:11)
at ClientRequest.emit (events.js:315:20)
at TLSSocket.socketErrorListener (_http_client.js:467:9)
at TLSSocket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:100:8)
at emitErrorCloseNT (internal/streams/destroy.js:68:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
type: 'system',
errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
}

and the iFrame shows this:
image

Is there anyway you can help me with this one?
Thank you so much!

Error with app.use(createIframe);

After installing this package and requiring it, when adding app.use(createIframe); compiler returns error:

throw new TypeError('app.use() requires a middleware function')

TypeError: app.use() requires a middleware function

my code:
var express = require('express'),
app = express(),
port = process.env.PORT || 3000,

const createIframe = require("node-iframe");
app.use(createIframe);

var server = app.listen(port);

Requires a middleware function error

Hi, thank you for this project! ๐Ÿ‘
However, I am getting an error when trying to start my server.

Here's the code:

`const express = require('express')
const createIframe = require('node-iframe')
const app = express()

app.use(createIframe)

app.get('/iframe', (req, res) => {
res.createIframe({
url: req.query.url,
})
})`

and I get this error

throw new TypeError('app.use() requires a middleware function')
^
TypeError: app.use() requires a middleware function

I am using node vv14.4.0

Any idea on how to solve this? :(
Thank you!!

Error when running server

Hello :)
Thank you for your work on this project.
I was looking for a way to do serverside-rendering for iframe and google lead me here.

There is the code I am trying to run

const express = require('express')
const createIframe = require("node-iframe")
const app = express();
const PORT = 8000;

app.use(createIframe)

app.get("/group1/dashboard_name_1", (req, res) => {
    res.createIframe({
      url: "http://dashboard_name_1:8501"
    })
  })
  
  app.get("/group1/dashboard_name_2", (req, res) => {
    res.createIframe({
      url: "http://dashboard_name_1:8502"
    })
  })

app.listen(PORT, () => {
  console.log(`โšก๏ธ[server]: Server is running at https://localhost:${PORT}`);

I got this error:

/node_modules/express/lib/application.js:210
    throw new TypeError('app.use() requires a middleware function')
    ^

TypeError: app.use() requires a middleware function
    at Function.use (node_modules/express/lib/application.js:210:11)
    at Object.<anonymous> (server.js:8:5)

any idea how to solve it ?

Thank you for your time if you reading this :)

Bypass asset and api loading CORS

I'm trying to put a sign-in page in an iframe. While this is somewhat working, the page isn't fully loading due to loading assets via a relative URL. The sign-in page is also making requests to an external API which is giving CORS SAMEORIGIN issues. I can work around the asset loading issues for the most part using request and deleting the 'X-Frame-Options' header, but cannot figure out how to bypass the API requests.

Is there a way I can work around this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.