Simple image host.
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.

index.node.js 448B

12345678910111213141516171819202122
  1. var fs = require("fs");
  2. module.exports = function(ctx) {
  3. var id = ctx.query.replace(/\..*/, "");
  4. if (!id)
  5. return ctx.err404();
  6. ctx.res.setHeader(
  7. "Cache-Control",
  8. "public, max-age="+ctx.conf.cache_max_age_images
  9. );
  10. var readStream = fs.createReadStream(ctx.conf.dir.imgs+"/"+id);
  11. readStream.pipe(ctx.res);
  12. readStream.on("error", function(err){
  13. if (err.code === "ENOENT")
  14. ctx.err404();
  15. else
  16. ctx.end(err.toString());
  17. });
  18. }