all repos — litestore @ 57a4a616c9824be24be31e70fa943c45b4cb4f10

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);
})();