tlrobinson / narwhal

[DEPRECATED] A JavaScript standard library, package manager, and more.
http://narwhaljs.org/
372 stars 16 forks source link

response header an all requests #109

Closed raresp closed 12 years ago

raresp commented 12 years ago

Hi,

What would I need to do to have my own Access-Control-Allow-Origin header in all responses?

Thank you, Rares

tlrobinson commented 12 years ago

Probably just a simple middleware like this:

function AccessControlMiddleware(app) {
    return function(env) {
        var response = app(env);
        HashP.set(response.headers, "Access-Control-Allow-Origin", "VALUE HERE");
        return response;
    }
}
raresp commented 12 years ago

Thanks for your quick response. Where shall I declare and register this function? Couldn't find any tutorials on how to do that. Thanks again.

Sent from my iPhone

On May 22, 2012, at 6:17 AM, Tom Robinson reply@reply.github.com wrote:

Probably just a simple middleware like this:

function AccessControlMiddleware(app) { return function(env) { var response = app(env); HashP.set(response.headers, "Access-Control-Allow-Origin", "VALUE HERE"); return response; } }


Reply to this email directly or view it on GitHub: https://github.com/tlrobinson/narwhal/issues/109#issuecomment-5838750

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.

raresp commented 12 years ago

I've added this function to jackconfig.js but I am getting an error:

ReferenceError: Can't find variable: HashP

On May 22, 2012, at 6:17 AM, Tom Robinson wrote:

Probably just a simple middleware like this:

function AccessControlMiddleware(app) { return function(env) { var response = app(env); HashP.set(response.headers, "Access-Control-Allow-Origin", "VALUE HERE"); return response; } }


Reply to this email directly or view it on GitHub: https://github.com/tlrobinson/narwhal/issues/109#issuecomment-5838750

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.


Rares Pop Chief Executive M: +40 745 028 869 | E: raresp@axz.ro | Skype: ra_axz www.azoth.eu | A: Grigore Alexandrescu 54, Bucuresti - Romania

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.

tlrobinson commented 12 years ago

I'm not sure if we still include HashP. This should work fine instead but it's not case sensitive:

response.headers["Access-Control-Allow-Origin"] = "VALUE HERE";