Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / http-proxy / examples / middleware / jsonp-middleware.js
1 var Store = require('../helpers/store')
2   , http = require('http')
3
4 //
5 // jsonp is a handy technique for getting around the limitations of the same-origin policy. 
6 // (http://en.wikipedia.org/wiki/Same_origin_policy) 
7 // 
8 // normally, to dynamically update a page you use an XmlHttpRequest. this has flakey support 
9 // is some browsers and is restricted by the same origin policy. you cannot perform XHR requests to
10 // someone else's server. one way around this would be to proxy requests to all the servers you want
11 // to xhr to, and your core server - so that everything has the same port and host.
12 // 
13 // another way, is to turn json into javascript. (which is exempt from the same origin policy) 
14 // this is done by wrapping the json object in a function call, and then including a script tag.
15 //
16 // here we're proxing our own JSON returning server, but we could proxy any server on the internet,
17 // and our client side app would be slurping down JSONP from anywhere.
18 // 
19 // curl localhost:1337/whatever?callback=alert
20 // alert([]) //which is valid javascript!
21 //
22 // also see http://en.wikipedia.org/wiki/JSONP#JSONP
23 //
24
25 http.createServer(new Store().handler()).listen(7531)
26
27 require('../../lib/node-http-proxy').createServer(
28   require('connect-jsonp')(true),
29   'localhost', 7531
30 ).listen(1337)