Created
May 31, 2016 15:11
-
-
Save ronfe/15e02390bea347898fb199947667d362 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 http = require("http"); | |
var url = require("url"); | |
var fs = require("fs"); | |
var server = http.createServer(function (request, response) { | |
var ua = request.headers['user-agent']; | |
console.log(ua); | |
var urlObj = url.parse(request.url, true); | |
var pathname = urlObj.pathname; | |
console.log(pathname) | |
var reg = /\.html/i; | |
if (reg.test(pathname)) { | |
console.log("passed " + pathname); | |
var con = fs.readFileSync("." + pathname, "utf8"); | |
response.writeHead(200, {"content-type": "text/html;charset=utf-8"}); | |
response.end(con); | |
} | |
//img/bg2.jpg | |
var reg1 = /\.jpg/i; | |
if (reg1.test(pathname)) { | |
var img = fs.readFileSync("." + pathname); | |
response.writeHead(200, {"content-type": "image/jpg;charset=utf-8;"}); | |
response.end(img); | |
} | |
}); | |
server.listen(8801, function () { | |
console.log("port 8801"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment