Skip to content

Commit

Permalink
Merge pull request #13 from mukhlisakbr/main
Browse files Browse the repository at this point in the history
add a simple static file server
  • Loading branch information
FirmanKurniawan authored Oct 2, 2022
2 parents 51c190d + 7081b45 commit 2085888
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions generate-uuid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const crypto = require('crypto');

const UUIDGeneratorNode = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
);
14 changes: 14 additions & 0 deletions static-file-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');
const http = require('http');

http.createServer((req, res) => {
fs.readFile(__dirname + req.url, (err, data) => {
if (err) {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.end('404: File not found');
} else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
}
});
}).listen(8000);

0 comments on commit 2085888

Please sign in to comment.