1234567891011121314151617181920212223242526272829 |
- var fs = require("fs");
- var http = require("http");
- var crypto = require("crypto");
-
- function Pic(path) {
- var content = fs.readFileSync(path);
- var hash = crypto.createHash("sha1").update(content).digest("hex");
-
- var self = {
- path: path,
- hash: hash,
- content: content
- }
-
- return self;
- }
-
- var currentPic = Pic("/home/martin/background.jpg");
-
- http.createServer((req, res) => {
- var hash = req.url.substring(1); // Remove the first / to get only hash
- console.log("got hash "+hash+", existing hash is "+currentPic.hash);
-
- if (hash === currentPic.hash) {
- res.end();
- } else {
- res.end(currentPic.content);
- }
- }).listen(8080);
|