-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic-server.js
More file actions
executable file
·46 lines (39 loc) · 1 KB
/
static-server.js
File metadata and controls
executable file
·46 lines (39 loc) · 1 KB
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
#!/usr/bin/env node
///STATIC SERVER 1
var express = require('express'), app = express.createServer();
app.configure(function() {
var hourMs = 1000*60*60;
app.use(express.static(__dirname + '/data', { maxAge: hourMs }));
app.use(express.directory(__dirname + '/data'));
app.use(express.errorHandler());
});
app.listen(8000);
///STATIC SERVER 2
var http = require('http'),fs=require('fs');
http.createServer(function (req, res) {
//var JS_Script = 'function Test() { alert("test success")}';
res.setHeader('content-type', 'application/json');
file="data/"+req.url;
fs.readFile(file, 'utf8', function(err, data) {
if (err){
try{
stat=fs.statSync(file);
if(stat.isDirectory()){
result={
"type":"dir",
"children":[]
}
files=fs.readdirSync(file);
for(f in files){
result.children.push(files[f]);
}
res.end(JSON.stringify(result));
}
}catch(error){
//throw err;
console.log("could find "+file);
}
}
res.end(data);
});
}).listen(9000);