Permalink
Browse files

disable session handlers instead of setting dummy auth token

  • Loading branch information...
1 parent 0bc458a commit c9c39cf4ed2354016a42a1bb02863d3fdec99c64 @rsms committed Aug 2, 2010
Showing with 13 additions and 6 deletions.
  1. +1 −1 examples/example1/server.js
  2. +12 −5 oui/server/index.js
@@ -6,7 +6,7 @@ var fs = require('fs'),
var server = oui.server.start({
port: 8080,
documentRoot: path.dirname(fs.realpathSync(__filename)) + '/public',
- authSecret: 'you should change this in a real app',
+ noSessionHandlers: true, // we don't use sessions or auth in this example
});
// In this example we store our messages in memory. In a real world app you
View
@@ -272,7 +272,7 @@ exports.createServer = function() {
server.maxRequestBodySize = 1024*1024*2; // 2 MB
// Standard handlers
- server.enableStandardHandlers = function(sessionPrefix) {
+ server.__proto__.enableSessionHandlers = function(sessionPrefix) {
if (!this.authSecret)
throw new Error('server.authSecret is not set');
if (!sessionPrefix) {
@@ -284,11 +284,17 @@ exports.createServer = function() {
this.GET(sessionPrefix+'/sign-in', 99, handlers.session.GET_signIn);
this.POST(sessionPrefix+'/sign-in', 99, handlers.session.POST_signIn);
this.GET(sessionPrefix+'/sign-out', 99, handlers.session.signOut);
+ }
+ server.__proto__.enableBasicHandlers = function() {
// Serve static files (priority 0/low)
this.GET(/^.+/, 0, handlers.static);
// Pass any OPTIONS request to allow CORS lookup (priority 0/low)
this.OPTIONS(/^.*/ , 0, handlers.noop);
}
+ server.__proto__.enableStandardHandlers = function(sessionPrefix) {
+ this.enableSessionHandlers(sessionPrefix);
+ this.enableBasicHandlers();
+ }
return server;
}
@@ -384,6 +390,7 @@ exports.start = function(options) {
'noCommandLineParsing',
'onCommandLineParseError',
'noStandardHandlers',
+ 'noSessionHandlers',
];
Object.keys(opt).forEach(function(k){
if (skipopts.indexOf(k) === -1) server[k] = opt[k];
@@ -392,10 +399,10 @@ exports.start = function(options) {
server.pathPrefix = server.pathPrefix.replace(/\/+$/, '');
// Unless noStandardHandlers...
if (!opt.noStandardHandlers) {
- server.enableStandardHandlers();
- server.enableStandardHandlers = function(){
- throw new Error('Standard handlers already enabled');
- };
+ if (!opt.noSessionHandlers) {
+ server.enableSessionHandlers(sessionPrefix);
+ }
+ server.enableBasicHandlers();
}
// listen
if (opt.sock) {

0 comments on commit c9c39cf

Please sign in to comment.