Last active
December 14, 2015 22:39
-
-
Save stephenhandley/5160214 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <h1>wordpress dot com</h1> | |
| <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
| <script> | |
| $(document).ready(function(){ | |
| var location = window.location.href; | |
| var node_app_url = "http://localhost:8000"; | |
| var node_path = node_app_url + "?wp_url=" + encodeURIComponent(location); | |
| var iframe = $("<iframe>").attr('src', node_path); | |
| $('body').append(iframe); | |
| }); | |
| </script> | |
| </html> | |
| <body> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var HTTP = require('http'); | |
| var URL = require('url'); | |
| var QueryString = require('querystring'); | |
| var port = 8000; | |
| var url_param = 'wp_url'; | |
| function contentForUrl (url) { | |
| var parsed_url = URL.parse(url); | |
| var query = QueryString.parse(parsed_url.query) | |
| var body_html; | |
| if (query.hasOwnProperty(url_param)) { | |
| var wp_url = query[url_param]; | |
| // | |
| // ... determine form / content to show based on wp_url here | |
| // or use https://github.com/mikeal/request to pull url content | |
| // | |
| body_html = '<div>form for ' + wp_url + '</div><form><input type="text"/><input type="submit"/></form>'; | |
| } else { | |
| body_html = url_param + ' query string param needs to be passed'; | |
| } | |
| console.log(wp_url); | |
| return '<html><body>' + body_html + '</body></html>' | |
| } | |
| function requestHandler (request, response) { | |
| var html = contentForUrl(request.url); | |
| response.writeHead(200, {"Content-Type": 'text/html'}); | |
| response.end(html); | |
| } | |
| HTTP.createServer(requestHandler).listen(port); | |
| console.log("listening on port " + port); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| node ./index.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment