all repos — litestore @ 20f1efa1f29fed91d9cbd13872537fb50eae5892

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