-
Notifications
You must be signed in to change notification settings - Fork 53
/
node server.js
53 lines (52 loc) · 1.72 KB
/
node server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Created by zhangyatao on 2014/6/9.
*/
var http = require("http");
var fs = require("fs");
var urlpara = require("url");
http.createServer(function (req, res) {
var urls = urlpara.parse(req.url);
var url = urls.pathname;
urls.query ? console.log(urls.query) : void 0;
if (url == "/") {
// readFile("junk/ajax.html", res);
// readFile("test_1.html", res);
readFile("SDK_Invoker.html", res);
} else if (url == "/qwer") {
readFile("SDK_Invoker.html", res);
// res.writeHead(200,
// {"Access-Control-Allow-Origin": "*",
// "Set-Cookie": "phpauth=asdfasdhfgahsdgf",
// "Access-Control-Request-Headers": "cookie",
// "Access-Control-Allow-Headers": "cookie",
// "Access-Control-Allow-Credentials": true});
// res.writeHead(200);
// res.end(JSON.stringify({name:'zhangyatao',age:23}));
} else if (url == "/register") {
console.log(req.headers);
res.writeHead(200,
{"Access-Control-Allow-Origin": "指定域名",
"Access-Control-Request-Headers": "cookie",
"Access-Control-Allow-Headers": "cookie",
"Access-Control-Allow-Credentials": true});
res.end();
}else if(url=="/xhr"){
res.writeHead(200);
setInterval(function(){
res.end("send")
},5000);
} else {
readFile(url.slice(1), res);
}
}).listen(1111);
function readFile(path, res) {
console.log(path);
fs.readFile(path, function (err, data) {
if (err) {
res.writeHead(404);
res.end("server error!not found this page!");
} else {
res.end(data);
}
});
}