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 376B

1234567891011121314151617
  1. var fs = require("fs");
  2. module.exports = function(ctx) {
  3. var id = ctx.query.replace(/\..*/, "");
  4. if (!id)
  5. return ctx.end(ctx.view("404"));
  6. var readStream = fs.createReadStream(ctx.conf.dir.imgs+"/"+id);
  7. readStream.pipe(ctx.res);
  8. readStream.on("error", function(err){
  9. if (err.code == "ENOENT")
  10. ctx.end(ctx.view("404"));
  11. else
  12. ctx.end(err.toString());
  13. });
  14. }