Pictures!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

server.js 635B

1234567891011121314151617181920212223242526272829
  1. var fs = require("fs");
  2. var http = require("http");
  3. var crypto = require("crypto");
  4. function Pic(path) {
  5. var content = fs.readFileSync(path);
  6. var hash = crypto.createHash("sha1").update(content).digest("hex");
  7. var self = {
  8. path: path,
  9. hash: hash,
  10. content: content
  11. }
  12. return self;
  13. }
  14. var currentPic = Pic("/home/martin/background.jpg");
  15. http.createServer((req, res) => {
  16. var hash = req.url.substring(1); // Remove the first / to get only hash
  17. console.log("got hash "+hash+", existing hash is "+currentPic.hash);
  18. if (hash === currentPic.hash) {
  19. res.end();
  20. } else {
  21. res.end(currentPic.content);
  22. }
  23. }).listen(8080);