From 290e99cdba0cc010ee32cb69d62550e5a9d2cd5f Mon Sep 17 00:00:00 2001 From: welefen Date: Tue, 18 Mar 2014 17:36:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9D=99=E6=80=81=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E4=B8=8B=E7=9A=84.html=E6=96=87=E4=BB=B6=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Conf/config.js | 2 +- lib/Lib/Behavior/CheckResourceBehavior.js | 9 +++++++-- lib/Lib/Core/Dispatcher.js | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/Conf/config.js b/lib/Conf/config.js index da4315e4..dfdbe8c2 100644 --- a/lib/Conf/config.js +++ b/lib/Conf/config.js @@ -9,7 +9,7 @@ module.exports = { pathname_prefix: "", //不解析的pathname前缀 app_tag_on: true, //是否支持标签功能 url_resource_on: true, //是否监听静态资源类请求 - url_resource_reg: /^resource\//, //判断是否是静态资源的正则 + url_resource_reg: /^(resource\/|favicon\.ico)/, //判断是否是静态资源的正则 post_json_content_type: ["application/json"], //post数据为json时的content-type url_route_on: true, //开启自定义路由功能 url_html_suffix: ".html", //url后缀,这样可以做到伪静态,对搜索引擎更友好 diff --git a/lib/Lib/Behavior/CheckResourceBehavior.js b/lib/Lib/Behavior/CheckResourceBehavior.js index 70a3dfba..58d47015 100644 --- a/lib/Lib/Behavior/CheckResourceBehavior.js +++ b/lib/Lib/Behavior/CheckResourceBehavior.js @@ -15,12 +15,16 @@ module.exports = Behavior(function(){ if (!RESOURCE_PATH || !this.options.url_resource_on || !this.http.pathname) { return false; }; + var pathname = this.http.pathname; + if (pathname.indexOf('/') === 0) { + pathname = pathname.substr(1); + }; var reg = C('url_resource_reg'); //通过正则判断是否是静态资源请求 - if (!reg.test(this.http.pathname)) { + if (!reg.test(pathname)) { return false; }; - var file = RESOURCE_PATH + "/" + this.http.pathname; + var file = RESOURCE_PATH + "/" + pathname; var res = this.http.res; if (fs.existsSync(file)) { var contentType = mime.lookup(file); @@ -34,6 +38,7 @@ module.exports = Behavior(function(){ res.statusCode = 404; res.end(); } + //返回一个pendding promise, 不让后续执行 return getDefer().promise; } } diff --git a/lib/Lib/Core/Dispatcher.js b/lib/Lib/Core/Dispatcher.js index 8c917a4a..20544e73 100644 --- a/lib/Lib/Core/Dispatcher.js +++ b/lib/Lib/Core/Dispatcher.js @@ -32,9 +32,9 @@ var Dispatcher = module.exports = Class(function(){ }, run: function(){ var self = this; - self.parsePathName(); - return tag("path_info", this.http).then(function(){ - return self.resourceCheck(); + return self.resourceCheck().then(function(){ + self.parsePathName(); + return tag("path_info", self.http); }).then(function(){ return self.routeCheck(); }).then(function(flag){