summaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/http-proxy/examples/middleware/jsonp-middleware.js
diff options
context:
space:
mode:
Diffstat (limited to 'vnfmarket/src/main/webapp/vnfmarket/node_modules/http-proxy/examples/middleware/jsonp-middleware.js')
-rw-r--r--vnfmarket/src/main/webapp/vnfmarket/node_modules/http-proxy/examples/middleware/jsonp-middleware.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/vnfmarket/src/main/webapp/vnfmarket/node_modules/http-proxy/examples/middleware/jsonp-middleware.js b/vnfmarket/src/main/webapp/vnfmarket/node_modules/http-proxy/examples/middleware/jsonp-middleware.js
new file mode 100644
index 00000000..15ab9ee0
--- /dev/null
+++ b/vnfmarket/src/main/webapp/vnfmarket/node_modules/http-proxy/examples/middleware/jsonp-middleware.js
@@ -0,0 +1,30 @@
+var Store = require('../helpers/store')
+ , http = require('http')
+
+//
+// jsonp is a handy technique for getting around the limitations of the same-origin policy.
+// (http://en.wikipedia.org/wiki/Same_origin_policy)
+//
+// normally, to dynamically update a page you use an XmlHttpRequest. this has flakey support
+// is some browsers and is restricted by the same origin policy. you cannot perform XHR requests to
+// someone else's server. one way around this would be to proxy requests to all the servers you want
+// to xhr to, and your core server - so that everything has the same port and host.
+//
+// another way, is to turn json into javascript. (which is exempt from the same origin policy)
+// this is done by wrapping the json object in a function call, and then including a script tag.
+//
+// here we're proxing our own JSON returning server, but we could proxy any server on the internet,
+// and our client side app would be slurping down JSONP from anywhere.
+//
+// curl localhost:1337/whatever?callback=alert
+// alert([]) //which is valid javascript!
+//
+// also see http://en.wikipedia.org/wiki/JSONP#JSONP
+//
+
+http.createServer(new Store().handler()).listen(7531)
+
+require('../../lib/node-http-proxy').createServer(
+ require('connect-jsonp')(true),
+ 'localhost', 7531
+).listen(1337)