Created
July 4, 2014 12:11
-
-
Save oberhamsi/eefc1d84e7d79249929b to your computer and use it in GitHub Desktop.
cors basicauth tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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