Created
August 28, 2010 22:42
-
-
Save mcepl/555657 to your computer and use it in GitHub Desktop.
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 Response = require('ringo/webapp/response').Response; | |
var log = require('ringo/logging').getLogger(module.id); | |
var config = require("config"); | |
function matchesREkey (obj, path) { | |
log.info("obj = " + obj.toSource()); | |
log.info("path = " + path); | |
for (var key in obj) { | |
if (new RegExp(key).test(path)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
/** | |
* Don't allow HTTP for authenticated pages | |
*/ | |
exports.middleware = function(app) { | |
return function(request) { | |
log.info("path = " + request.pathInfo); | |
log.info("scheme = " + request.scheme); | |
log.info("matchesREkey = " + matchesREkey(config.auth, request.pathInfo)); | |
if (matchesREkey(config.auth, request.pathInfo) && | |
(request.scheme === 'http')) { | |
log.info('redirecting to https!'); | |
return { | |
status: 303, | |
headers: {location: 'https://' + request.host + ':8443' + request.pathInfo}, | |
body: [] | |
}; | |
} | |
return app(request); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var filestore = require("ringo/storage/filestore");
var storePath = 'db';
exports.store = new filestore.Store(storePath);
exports.httpConfig = {
staticDir: 'static'
};
exports.urls = [
['/', 'actions'],
['/admin/', 'adminactions']
];
exports.middleware = [
'ringo/middleware/gzip',
'ringo/middleware/etag',
'ringo/middleware/responselog',
'middleware/onlyhttps',
'ringo/middleware/basicauth',
'ringo/middleware/error',
'ringo/middleware/notfound'
];
exports.auth = {
'/admin/': {
matej: "7c9c0fb8d0c1624a3a280580d279dada313ed945" // "kyrios"
}
};
exports.app = require('ringo/webapp').handleRequest;
exports.macros = [
require('ringo/skin/macros'),
require('ringo/skin/filters')
];
exports.charset = 'UTF-8';
exports.contentType = 'text/html';