all repos — litestore @ 0a0fdb3e02ad9bb5373f55a49d19c5f763df3bfc

A minimalist nosql document store.

src/litestorepkg/examples/system/middleware/validate.js

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
(function() {
  var id = $req.path.replace(/^\/docs\//, "");
  var valid = /[A-Z]{2}[0-9]{3}[A-Z]{2}/;
  if (!id.match(valid)) {
    $res.content = {
      error: "Invalid number plate"
    };
    $res.code = 400;
    return true;
  }
  $ctx.existing = !!($store.get("docs", id).code == 200);
})();