Skip to content

Commit 8d24eaa

Browse files
committed
Merge pull request #7 from clevertension/master
minor fix for visit directory
2 parents 3c42b63 + b60bdb1 commit 8d24eaa

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

tools/server.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,31 @@ http.createServer(function (request, response) {
1818
var uri = url.parse(request.url).pathname,
1919
filename = path.join(__dirname, '..', uri);
2020

21-
fs.exists(filename, function (exists) {
22-
if (!exists) {
23-
response.writeHead(404, {'Content-Type': 'text/plain'});
24-
response.write('404 Not Found\n');
25-
response.end();
26-
return;
27-
}
21+
if(!fs.lstatSync(filename).isDirectory()) {
22+
fs.exists(filename, function (exists) {
23+
if (!exists) {
24+
response.writeHead(404, {'Content-Type': 'text/plain'});
25+
response.write('404 Not Found\n');
26+
response.end();
27+
return;
28+
}
2829

29-
var type = filename.split('.');
30-
type = type[type.length - 1];
30+
var type = filename.split('.');
31+
type = type[type.length - 1];
3132

32-
response.writeHead(200, { 'Content-Type': types[type] + '; charset=utf-8' });
33-
fs.createReadStream(filename).pipe(response);
34-
});
33+
response.writeHead(200, { 'Content-Type': types[type] + '; charset=utf-8' });
34+
fs.createReadStream(filename).pipe(response);
35+
});
36+
} else {
37+
/**
38+
* if users visit the site such as http://localhost:8888
39+
* then lead them to http://localhost:8888/www/app.html
40+
*
41+
*/
42+
response.writeHead(200, {'Content-Type': 'text/html'});
43+
response.write('Please visit <a href="www/app.html">here</a>\n');
44+
response.end();
45+
}
3546
}).listen(parseInt(port, 10));
3647

3748
console.log('Static file server running at\n => http://localhost:' + port + '/\nCTRL + C to shutdown');

0 commit comments

Comments
 (0)