Skip to content

Instantly share code, notes, and snippets.

@oberhamsi
Created July 4, 2014 12:11
Show Gist options
  • Save oberhamsi/eefc1d84e7d79249929b to your computer and use it in GitHub Desktop.
Save oberhamsi/eefc1d84e7d79249929b to your computer and use it in GitHub Desktop.
cors basicauth tester
var {Application} = require("stick");
var {Server} = require("ringo/httpserver");
var response = require("ringo/jsgi/response");
var app = exports.app = new Application();
app.configure("cors", "route");
app.cors({
allowOrigin: ['http://orf.at', 'http://www.orf.at', 'http://simon.orf.at'],
allowCredentials: true,
allowMethods: ['GET'],
allowHeaders: ['Authorization'],
maxAge: 0
});
app.options('/', function(req) {
console.log(req.method);
console.dir(req.headers);
console.log('----');
return response.ok('we got options');
});
app.get('/', function(req) {
console.log(req.method);
console.dir(req.headers);
console.log('----');
if (req.headers.authorization) {
return response.ok('you are authorized!');
}
return response.unauthorized('gimme some auth!');
});
//Script run from command line
if (require.main === module) {
var httpServer = new Server({
"appName": "app",
"appModule": module.resolve("./main")
});
httpServer.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment