<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Hi Luke, CORS was recently added on aerogear controller.</div><div><br></div><div>Could we put pipeline and controller together?<br><br><br><div>- Bruno</div></div><div><br>On Dec 6, 2012, at 6:31 PM, Lucas Holmquist &lt;<a href="mailto:lholmqui@redhat.com">lholmqui@redhat.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><p style="margin-top: 0px !important; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; "><em style="margin: 0px; padding: 0px; line-height: 1.4em; ">can also be seen here&nbsp;<a href="https://gist.github.com/4227377">https://gist.github.com/4227377</a></em></p><p style="margin-top: 0px !important; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; "><em style="margin: 0px; padding: 0px; line-height: 1.4em; "><br></em></p><p style="margin-top: 0px !important; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; "><em style="margin: 0px; padding: 0px; line-height: 1.4em; ">This gist relates to AEROGEAR-534,&nbsp;<a href="https://issues.jboss.org/browse/AEROGEAR-534" style="margin: 0px; padding: 0px; line-height: 1.4em; color: rgb(65, 131, 196); text-decoration: none; ">https://issues.jboss.org/browse/AEROGEAR-534</a></em></p><p style="margin: 15px 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; "><em style="margin: 0px; padding: 0px; line-height: 1.4em; ">I created a node.js server that handles CORS and jsonp for my testing</em></p><h3 style="margin: 20px 0px 10px; padding: 0px; line-height: 1.4em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(221, 221, 221); -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 18px; font-family: helvetica, arial, freesans, clean, sans-serif; text-align: left; "><a name="cross-domain-support" class="anchor" href="https://gist.github.com/4227377#cross-domain-support" style="margin: 0px 0px 0px -30px; padding: 0px 0px 0px 30px; line-height: 1.4em; color: rgb(65, 131, 196); text-decoration: none; display: block; cursor: pointer; position: absolute; top: 0px; left: 0px; bottom: 0px; "></a>Cross Domain Support</h3><p style="margin: 0px 0px 15px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; ">To do cross domain request, i've modified aerogear.js a bit.</p><p style="margin: 15px 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; ">I've added a new settings variable, settings.crossdomain, that can be mixed. If set to true, it will default to CORS, to override to jsonp set settings.crossdomain.type = "jsonp"</p><pre style="margin-top: 15px; margin-bottom: 15px; padding: 6px 10px; font-size: 13px; line-height: 19px; font-family: Monaco, 'Courier New', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; background-color: rgb(248, 248, 248); border: 1px solid rgb(204, 204, 204); overflow: auto; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; text-align: left; "><code style="margin: 0px; padding: 0px; font-size: 12px; line-height: 1.4em; font-family: Monaco, 'Courier New', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; border: none; background-color: transparent; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; ">var pipeline = AeroGear.Pipeline();

    jsonp = pipeline.add( {
            name: "jsonp",
            settings: {
                baseURL: "<a href="http://localhost:8080">http://localhost:8080</a>",
                endpoint: "/",
                crossdomain: {
                    type: "jsonp",
                    jsonp: "jsonp" //this is optional and will default to callback, jquery default
                }
            }
        });

    cors = pipeline.add( {
            name: "cors",
            settings: {
                baseURL: "<a href="http://localhost:8080">http://localhost:8080</a>",
                endpoint: "/",
                crossdomain: true
            }
        });
</code></pre><p style="margin: 15px 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; ">If the user wants to use CORS, settings.crossdomain = true, but there browser doesn't support CORS, then AeroGear.Ajax will fallback to jsonp</p><h3 style="margin: 20px 0px 10px; padding: 0px; line-height: 1.4em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(221, 221, 221); -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 18px; font-family: helvetica, arial, freesans, clean, sans-serif; text-align: left; "><a name="cors" class="anchor" href="https://gist.github.com/4227377#cors" style="margin: 0px 0px 0px -30px; padding: 0px 0px 0px 30px; line-height: 1.4em; color: rgb(65, 131, 196); text-decoration: none; display: block; cursor: pointer; position: absolute; top: 0px; left: 0px; bottom: 0px; "></a>CORS</h3><p style="margin: 0px 0px 15px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; ">since IE9 doesn't use the same thing as the rest of the browser world, i add in a small lib,<a href="https://github.com/jaubourg/ajaxHooks" style="margin: 0px; padding: 0px; line-height: 1.4em; color: rgb(65, 131, 196); text-decoration: none; ">https://github.com/jaubourg/ajaxHooks</a>, in the external/ actually just the xdr.js file</p><p style="margin: 15px 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; ">Although i haven't actually tested that it works</p><h3 style="margin: 20px 0px 10px; padding: 0px; line-height: 1.4em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(221, 221, 221); -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 18px; font-family: helvetica, arial, freesans, clean, sans-serif; text-align: left; "><a name="aerogearajax" class="anchor" href="https://gist.github.com/4227377#aerogearajax" style="margin: 0px 0px 0px -30px; padding: 0px 0px 0px 30px; line-height: 1.4em; color: rgb(65, 131, 196); text-decoration: none; display: block; cursor: pointer; position: absolute; top: 0px; left: 0px; bottom: 0px; "></a>AeroGear.Ajax</h3><p style="margin: 0px 0px 15px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; ">The majority of the changes happen in the AeroGear.Ajax function</p><p style="margin: 15px 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; ">Here is the commit for this</p><p style="margin: 15px 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; "><a href="https://github.com/lholmquist/aerogear-js/commit/d3d3ecaac1d2648f37d66b46f7e776029b2a3517" style="margin: 0px; padding: 0px; line-height: 1.4em; color: rgb(65, 131, 196); text-decoration: none; ">https://github.com/lholmquist/aerogear-js/commit/d3d3ecaac1d2648f37d66b46f7e776029b2a3517</a></p><p style="margin: 15px 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; ">At the moment the only overridable options in the crossdomain object are jsonp related. I guess this would be the place to add CORS options, if we wanted to</p><p style="margin: 15px 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; ">Interestingly enough, if you don't specify any of the new settings, CORS will work, if the server supports it, out of the box.</p><p style="margin: 15px 0px; padding: 0px; line-height: 1.4em; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; text-align: left; ">This is my simple node.js server</p><pre style="margin-top: 15px; margin-bottom: 0px !important; padding: 6px 10px; font-size: 13px; line-height: 19px; font-family: Monaco, 'Courier New', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; background-color: rgb(248, 248, 248); border: 1px solid rgb(204, 204, 204); overflow: auto; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; text-align: left; "><code style="margin: 0px; padding: 0px; font-size: 12px; line-height: 1.4em; font-family: Monaco, 'Courier New', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; border: none; background-color: transparent; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; ">var express = require( "express" );
var app = express();

app.all( "/", function(request,response) {

// When dealing with CORS (Cross-Origin Resource Sharing)
// requests, the client should pass-through its origin (the
// requesting domain). We should either echo that or use *
// if the origin was not passed.
var origin = (request.headers.origin || "*");

// Check to see if this is a security check by the browser to
    // test the availability of the API for the client. If the
    // method is OPTIONS, the browser is check to see to see what
    // HTTP methods (and properties) have been granted to the
    // client.
    if (request.method.toUpperCase() === "OPTIONS"){


        // Echo back the Origin (calling domain) so that the
        // client is granted access to make subsequent requests
        // to the API.
        response.status( 204 );
        response.header(
            {
                "access-control-allow-origin": origin,
                "access-control-allow-methods": "GET, PUT, DELETE, OPTIONS",
                "access-control-allow-headers": "content-type, accept",
                "access-control-max-age": 10, // Seconds.
                "content-length": 0
            }
        );
    }
    // End the response - we're not sending back any content.
    response.status( 200 );
    response.header(
                {
                    "access-control-allow-origin": origin,
                    "content-type": "application/json"
                }
            );
    var callback = request.query.callback || request.query.jsonp;
    if( callback ) {
        response.send( callback + "({response:'stuff'})");
    } else {
        response.send( {response:'stuff'});
    }


});

app.listen( 8080 );

// Debugging:
console.log( "Node.js listening on port 8080" );</code></pre><div><br></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>aerogear-dev mailing list</span><br><span><a href="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</a></span><br><span><a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a></span><br></div></blockquote></body></html>