-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
155 lines (143 loc) · 3.73 KB
/
index.html
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<!-- disable zooming -->
<meta name="viewport" content="width=device-width,initial-scale=1.0, user-scalable=0" />
<script>
$SYSVARS='';
var gui = require('nw.gui');
var win = gui.Window.get();
win.showDevTools();
//win.setAlwaysOnTop(1);
win.setResizable(0);
win.height=screen.availHeight;
win.width=screen.availWidth;
win.x=0;
win.y=0;
</script>
<style>
html,body,input,textarea{
font-family:"微软雅黑";
color: #444;
text-shadow: 0px 0px 20px #444;
}
body{
background: #eee;
}
input{
color: #444;
}
::selection {
background:rgba(0,0,0,0.8);
color:#fff;
}
::-moz-selection {
background:rgba(0,0,0,0.8);
color:#fff;
}
::-webkit-selection {
background:rgba(0,0,0,0.8);
color:#fff;
}
::-webkit-scrollbar {
width: 15px;
}
::-webkit-scrollbar-track {
background-color:rgba(255,255,255,0.3);
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
background-color:rgba(255,255,255,0.6);
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
#close{
cursor:pointer;
display:inline-block;
position: absolute;
top:0px;
right:0px;
color:#eee;
}
</style>
</head>
<body>
<iframe id="playbox" src="" style="position:absolute;top:0px;left:0px;width:100%;height:100%;border:none;"></iframe>
<div id="close">X</div>
</body>
<script type="text/javascript">
var nodegrass = require('nodegrass');
var http = require('http');
var folderPath='web';
var url = require('url');
var fs = require("fs");
var path = require('path');
var qs = require('querystring');
var mime=require('mime');
var Cookies=require('cookies');
var BufferHelper = require('bufferhelper');
expiresmaxAge=606024365;
var mime=require('mime');
PORT=10086;
SERVER='127.0.0.1';
function showup(){
document.getElementById("playbox").src="http://127.0.0.1:10086/index.html";
}
document.getElementById("close").addEventListener("click",function(){
window.opener=null;
window.open('','_self');
window.close();
//gui.App.quit()
},false);
var server = http.createServer(function (req, res) {
try{
var cookies = new Cookies( req, res);
var path = url.parse(req.url);
var parameter = qs.parse(path.query);
if(path.pathname==""||path.pathname=="/"){
path.pathname="/index.html";
}
var filePath = folderPath + path.pathname;
fs.stat(filePath, function (err, stat) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/plain'});
res.end();
return;
}
var expires = new Date();
expires.setTime(expires.getTime() + expiresmaxAge*1000);
var lastModified = stat.mtime.toUTCString();
if (req.headers['ifModifiedSince'] && lastModified == req.headers['ifModifiedSince']) {
response.writeHead(304, "Not Modified");
res.end();
}else{
fs.readFile(filePath, "binary", function(err, file) {
var mimeType = mime.lookup(filePath);
console.log(filePath+":"+mimeType);
res.setHeader("Expires", expires.toUTCString());
res.setHeader("Cache-Control", "max-age=" + expiresmaxAge);
res.setHeader("Last-Modified", lastModified);
res.writeHead(200, {'Content-Type': mimeType} );
res.write(file,"binary");
res.end();
});
}
});
}catch(e){
//todo: add log
console.log(e);
res.writeHead(500, {'Content-Type': 'text/plain'});
res.write('500 Internal server error\n');
res.end();
}
});
server.listen(PORT, SERVER);
window.onload=function(){
setTimeout(function(){
showup();
},5000)
}
</script>
</html>