Skip to content
Browse files

- added "ignore" to config to reply a 404 to certain files, ignore it…

…ems can use wildcards
  • Loading branch information...
1 parent 3be0f25 commit 1538d1a3054df1d5ff02ea44da4a41f7a4238076 @dresende committed Jun 28, 2011
Showing with 22 additions and 0 deletions.
  1. +17 −0 core/utils.js
  2. +4 −0 navajo.conf
  3. +1 −0 www/default/forbidden.txt
View
17 core/utils.js
@@ -36,6 +36,15 @@ function loadConfig(config_path, cb) {
if (typeof config.plugins != "object") {
config.plugins = {};
}
+ if (config.ignore) {
+ for (var i = 0; i < config.ignore.length; i++) {
+ config.ignore[i] = config.ignore[i].replace(/([.?+^$[\]\\(){}-])/g, "\\$1")
+ .replace("*", ".*");
+ if (config.ignore[i][0] == "/") {
+ config.ignore[i] = "^" + config.ignore[i];
+ }
+ }
+ }
print.setLogging(config.log);
@@ -86,6 +95,14 @@ function parseHostPort(hostport, def) {
}
function processRequest(req, res) {
+ if (config.ignore) {
+ for (var i = 0; i < config.ignore.length; i++) {
+ var exp = new RegExp(config.ignore[i], "i");
+ if (exp.exec(req.url)) {
+ return replyError(404, req, res);
+ }
+ }
+ }
replyTo(req.url, req, res);
}
View
4 navajo.conf
@@ -11,6 +11,10 @@
"default" : "www/default",
"*vhost" : "www/vhost--*"
},
+ "ignore" : [
+ "*.txt",
+ "/core"
+ ],
"mime" : {
"application/x-httpd-php" : "php",
"application/x-httpd-js" : "js",
View
1 www/default/forbidden.txt
@@ -0,0 +1 @@
+This file is forbidden

0 comments on commit 1538d1a

Please sign in to comment.
Something went wrong with that request. Please try again.