I have the following node proxy server set up to strip out the page name from a request made from one web app and use it to display page info in a second web app. It works fine but for every request intercepted a new browser is opened up. Is there anyway to detect if an internet explorer browser is aleady open so i can use that?
var http = require('http'),
httpProxy = require('http-proxy'),
request = require('request'),
open = require('open');
//
// Create proxy server
//
httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(9085);
//
// Create target server
//
http.createServer(function (req, res) {
if (req.method=='GET') {
if (req.url.indexOf("Page.do") > -1) {
var temp = req.url.split("Page.do")[0].split("/");
var pageName = temp[temp.length - 1];
var docURL = "http://localhost:9081/mysecondwebapp/pages/" + pageName + ".html";
open(docURL, "iexplore");
};
};
}).listen(9000);
Here is an iframe + socket.io solution I've talking in comments. I used express.io module because I'm more familiar with it than with original socket.io module.
Here is a server-side code:
app = require('express.io')();
app.http().io();
var base = 'http://www.w3schools.com/tags/tag_';
// Send the client html.
app.get('/', function(req, res) {
res.sendfile(__dirname + '/client.html');
})
app.post('/:tag', function(req, res) {
// Send new url to the all active clients
app.io.broadcast('update', {
url: base + req.params.tag + '.asp'
});
// End original request
res.send(200);
})
app.listen(9000);
and client.html with iframe and simple JS snippet:
<!DOCTYPE html>
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<style type="text/css">
body iframe {
overflow: hidden;
overflow-x: hidden;
overflow-y: hidden;
position: absolute;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
top: 0;
left: 0;
right: 0;
bottom: 0
}
</style>
</head>
<body>
<iframe id="frame" frameborder="0" height="100%" width="100%"></iframe>
<script>
io = io.connect();
frame = document.getElementById('frame');
io.on('update', function(data) {
frame.src = data.url;
});
</script>
</body>
</html>
Here is how it works:
node.js server and navigate to localhost:9000 in your browser.curl or any other http utility to send POST request to localhost:9000/iframe.w3schools page for iframe tag displayed in previously opened window.I hope this simple example will help you.
Here are all the links I used to write it:
w3schools help and tutorialsexpress.io examples, and especially broadcasting example