-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathapp.js
39 lines (37 loc) · 1.02 KB
/
app.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
var http = require('http'),
fs = require('fs');
var port = 9284;//端口号
/*
这是一个简单的服务器
主要作用是 启动这个静态文件
只支持 加载png/js
默认跳转也面 只有首页
*/
var server = http.createServer(function(req, res){
if('GET' == req.method){//进入游戏页
if('/' == req.url){
var deviceAgent = req.headers['user-agent'].toLowerCase();
var agentID = deviceAgent.match(/(iphone|ipod|ipad|android)/);
if(agentID){
serve(__dirname + '/shake.html', 'text/html');
}else{
serve(__dirname + '/index.html', 'text/html');
}
}else if('/images/' == req.url.substr(0,8)){
serve(__dirname + req.url, 'image/png');
}
}else{
res.writeHead(404);
res.end('Not found');
}
function serve(path, type){
res.writeHead(200, {'Content-Type': type});
fs.createReadStream(path).pipe(res);
}
function getType(url){
return url.substring(url.lastIndexOf('.'), url.length);
}
});
server.listen(port, function(){
console.log('Express server listening on port ' + port);
});