all repos — litestore @ a21ea4c45adf73ff689088392735cb1a97ee94a9

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