From 682f8f451d7b0e4036b12b2411b71ced5a80de47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=86=E8=AE=AF=E5=9C=A8=E7=BA=BF?= Date: Fri, 24 Oct 2014 22:28:07 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwindows=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=8Bcss=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 6 ++++++ wide-ide.bat | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 wide-ide.bat diff --git a/main.go b/main.go index ca6b9d9..7ffc49b 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "runtime" "strconv" "time" + "mime" "github.com/b3log/wide/conf" "github.com/b3log/wide/editor" @@ -48,6 +49,11 @@ func init() { // 定时检查无效会话 session.FixedTimeRelease() + + //解决Windows环境下问题 + mime.AddExtensionType(".css", "text/css") + mime.AddExtensionType(".js", "application/x-javascript") + mime.AddExtensionType(".json", "application/json") } // 登录. diff --git a/wide-ide.bat b/wide-ide.bat new file mode 100644 index 0000000..570da4e --- /dev/null +++ b/wide-ide.bat @@ -0,0 +1,3 @@ +go install +wide +pause \ No newline at end of file From 5e46dd3eb533b55335db64db1cac89520b1d0b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=86=E8=AE=AF=E5=9C=A8=E7=BA=BF?= Date: Fri, 24 Oct 2014 22:35:49 +0800 Subject: [PATCH 2/3] update --- main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 7ffc49b..a2a2359 100644 --- a/main.go +++ b/main.go @@ -49,11 +49,6 @@ func init() { // 定时检查无效会话 session.FixedTimeRelease() - - //解决Windows环境下问题 - mime.AddExtensionType(".css", "text/css") - mime.AddExtensionType(".js", "application/x-javascript") - mime.AddExtensionType(".json", "application/json") } // 登录. @@ -279,6 +274,12 @@ func aboutHandler(w http.ResponseWriter, r *http.Request) { // 主程序入口. func main() { + + //解决Windows环境下问题 + mime.AddExtensionType(".css", "text/css") + mime.AddExtensionType(".js", "application/x-javascript") + mime.AddExtensionType(".json", "application/json") + runtime.GOMAXPROCS(conf.Wide.MaxProcs) defer glog.Flush() From d11db2f3af6feec7dec60eede90799a3fbac5ab6 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 24 Oct 2014 23:51:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?mime=20=E7=B1=BB=E5=9E=8B=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @admpub 在你的 pr 基础上做了一些小重构 --- main.go | 19 ++++++++++++------- wide-ide.bat => wide.bat | 4 +++- 2 files changed, 15 insertions(+), 8 deletions(-) rename wide-ide.bat => wide.bat (66%) diff --git a/main.go b/main.go index a2a2359..5e70a17 100644 --- a/main.go +++ b/main.go @@ -5,11 +5,11 @@ import ( "flag" "html/template" "math/rand" + "mime" "net/http" "runtime" "strconv" "time" - "mime" "github.com/b3log/wide/conf" "github.com/b3log/wide/editor" @@ -274,14 +274,10 @@ func aboutHandler(w http.ResponseWriter, r *http.Request) { // 主程序入口. func main() { - - //解决Windows环境下问题 - mime.AddExtensionType(".css", "text/css") - mime.AddExtensionType(".js", "application/x-javascript") - mime.AddExtensionType(".json", "application/json") - runtime.GOMAXPROCS(conf.Wide.MaxProcs) + initMime() + defer glog.Flush() // IDE @@ -387,3 +383,12 @@ func panicRecover(handler func(w http.ResponseWriter, r *http.Request)) func(w h handler(w, r) } } + +// 初始化 mime. +// +// 有的操作系统(例如 Windows XP)上运行时根据文件后缀获取不到对应的 mime 类型,会导致响应的 HTTP content-type 不正确。 +func initMime() { + mime.AddExtensionType(".css", "text/css") + mime.AddExtensionType(".js", "application/x-javascript") + mime.AddExtensionType(".json", "application/json") +} diff --git a/wide-ide.bat b/wide.bat similarity index 66% rename from wide-ide.bat rename to wide.bat index 570da4e..4fdf252 100644 --- a/wide-ide.bat +++ b/wide.bat @@ -1,3 +1,5 @@ go install + wide -pause \ No newline at end of file + +pause