You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Imagine the scenario: you've built a lovely web app for a business, who later insists it goes live within an iframe of their corp website. You resist, but you're ultimatley forced to bastardize your app to make it work.
4
+
5
+
[node-iframe-replacement](https://github.com/john-doherty/node-iframe-replacement) is the compromise. A small node server that grabs the source code of an external website and injects your content - thus allowing you to host your app on a subdomain and without an iframe. Changes to the external site _(navigation etc)_ are automatically picked up every 5 minutes and reflected in your app.
6
+
7
+
You can now argue that you're web app can remain synced with the corp website without an iframe.
8
+
9
+
10
+
## Installation
11
+
12
+
```bash
13
+
$ npm install --save node-iframe-replacement
14
+
```
15
+
16
+
## Example usage
17
+
18
+
The example below will request the [BBC News](http://www.bbc.co.uk/news) home page and replace the contents of **div[data-entityid="container-top-stories#1"]** with the contents of the view
19
+
20
+
```js
21
+
var iframeReplacement =require('node-iframe-replacement');
22
+
23
+
// replace res.render with iframe replacement version
24
+
app.use(iframeReplacement);
25
+
26
+
// create a regular express route
27
+
app.get('/', function(req, res){
28
+
29
+
// respond to this request with our fake-new content embedded within the BBC News home page
30
+
res.merge('fake-news', {
31
+
sourceUrl:'http://www.bbc.co.uk/news', // external url to fetch
32
+
sourcePlaceholder:'div[data-entityid="container-top-stories#1"]'// css selector to inject our content into

56
+
57
+
## Output
58
+
59
+

60
+
61
+
## Auto base tag injection
62
+
63
+
To ensure the source scripts, styles and images load witin your site a base tag is automatically injected ```<base href="http://www.bbc.co.uk/news" />```.
64
+
65
+
Because of this, you need to ensure all the links within your conent are absolute.
0 commit comments