Skip to content

Commit

Permalink
Changing default JSON output to have no padding, moving regex.id & …
Browse files Browse the repository at this point in the history
…`regex.hypermedia` definitions into `config.json` & allowing for overriding of any default from there
  • Loading branch information
avoidwork committed Dec 29, 2016
1 parent 5d66a2b commit fe87c72
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ This is a sample configuration for Tensō, without authentication or SSL. This w
},
"port": 8000, /* Optional */
"routes": require("./routes.js"), /* Required! */
"regex": {
"hypermedia": "[a-zA-Z]+_(guid|uuid|id|url|uri)$", /* Optional, changes hypermedia detection / generation */
"id": "^(_id|id)$" /* Optional, changes hypermedia detection / generation */
},
"session": { /* Optional */
"secret": null,
"store": "memory", /* "memory" or "redis" */
Expand Down
8 changes: 6 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"address": "127.0.0.1",
"hostname": "127.0.0.1",
"json": 2,
"json": 0,
"logging": {
"level": "info",
"enabled": true,
Expand Down Expand Up @@ -127,5 +127,9 @@
}
},
"title": "Tensō Browsable API",
"template": ""
"template": "",
"regex": {
"hypermedia": "[a-zA-Z]+_(guid|uuid|id|url|uri)$",
"id": "^(_id|id)$"
}
}
47 changes: 26 additions & 21 deletions lib/regex.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
const regex = {
body: /POST|PUT|PATCH/i,
body_split: /&|=/,
collection: /(.*)(\/.*)$/,
encode_form: /application\/x-www-form-urlencoded/,
encode_json: /application\/json/,
get_rewrite: /HEAD|OPTIONS/i,
has_param: /\/:(\w*)/,
hypermedia: /[a-zA-Z]+_(guid|uuid|id|url|uri)$/,
id: /^(_id|id)$/i,
json_wrap: /^[\[\{]/,
leading: /.*\//,
mimetype: /;.*/,
modify: /DELETE|PATCH|POST|PUT/,
private: /private/,
scheme: /^(\w+\:\/\/)|\//,
trailing: /_.*$/,
trailing_s: /s$/,
trailing_slash: /\/$/,
trailing_y: /y$/
};
const path = require("path"),
cfg = require(path.join(__dirname, "..", "config.json")),
iterate = require(path.join(__dirname, "iterate.js")),
regex = {
body: /POST|PUT|PATCH/i,
body_split: /&|=/,
collection: /(.*)(\/.*)$/,
encode_form: /application\/x-www-form-urlencoded/,
encode_json: /application\/json/,
get_rewrite: /HEAD|OPTIONS/i,
has_param: /\/:(\w*)/,
json_wrap: /^[\[\{]/,
leading: /.*\//,
mimetype: /;.*/,
modify: /DELETE|PATCH|POST|PUT/,
private: /private/,
scheme: /^(\w+\:\/\/)|\//,
trailing: /_.*$/,
trailing_s: /s$/,
trailing_slash: /\/$/,
trailing_y: /y$/
};

iterate(cfg.regex || {}, (value, key) => {
regex[key] = new RegExp(value, "i");
});

module.exports = regex;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tenso",
"description": "Tensō is an elastic REST API gateway for node.js",
"version": "4.2.0",
"version": "4.3.0",
"homepage": "http://avoidwork.github.io/tenso",
"author": "Jason Mulligan <[email protected]>",
"repository": {
Expand Down

0 comments on commit fe87c72

Please sign in to comment.