From 78c2927b277d291afb425d9b30b387c4ead6303d Mon Sep 17 00:00:00 2001 From: iCoolchar Date: Wed, 2 Nov 2016 22:46:10 +0800 Subject: [PATCH] fix Chinese character show in browser --- app.js | 8 +++++--- demo/index.html | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 5792f96..dde3e93 100644 --- a/app.js +++ b/app.js @@ -39,13 +39,15 @@ http.createServer(function(req, res){ if(fs.existsSync(filePath)){ res.write(fs.readFileSync(filePath)); } else { - res.write("

小胡子哥告诉你:404了~

"); + res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"}); + res.write("

小胡子哥告诉你:404了~

", 'utf-8'); } res.end(); } else { - res.write("

小胡子哥告诉你:404了~

"); + res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"}); + res.write("

小胡子哥告诉你:404了~

", 'utf-8'); res.end(); } }).listen(PORT, function(){ console.log('Listen at http://0.0.0.0:' + PORT); -}); \ No newline at end of file +}); diff --git a/demo/index.html b/demo/index.html index dbde546..f605ff8 100644 --- a/demo/index.html +++ b/demo/index.html @@ -1,5 +1,6 @@ +