Skip to content

Commit 70b1024

Browse files
author
Andrey
committed
Added automatic restarting, and secured files listing.
1 parent 6fccb55 commit 70b1024

File tree

4 files changed

+902
-4
lines changed

4 files changed

+902
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# node-modules
2+
node_modules/

index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,20 @@ http
5050
if (err) {
5151
return console.log('Unable to scan directory: ' + err);
5252
}
53+
54+
var index = pathname.lastIndexOf('/');
55+
var reqPath = pathname.substring(index + 1);
56+
57+
if (reqPath === 'files') {
58+
res.setHeader('Content-type', mimeType['.json'])
59+
res.end(JSON.stringify(files));
60+
} else {
61+
res.writeHead(404, {
62+
'Content-type': 'text/html'
63+
});
64+
res.end(`<h1>Incorrect Request</h1>`);
65+
}
5366

54-
res.setHeader('Content-type', mimeType['.json'])
55-
res.end(JSON.stringify(files));
5667
});
5768
}
5869

0 commit comments

Comments
 (0)