Comparing version 0.12.4 to 0.12.5
@@ -23,8 +23,2 @@ const assert = require('assert'); | ||
if(seg[0] == '('){ | ||
regexp += seg; | ||
r.params.push('path'); | ||
return; | ||
} | ||
regexp += '\\/' + seg; | ||
@@ -48,2 +42,5 @@ }); | ||
function buildStack(context, chain){ | ||
chain.length > 1 && | ||
context.log.warn('Building routes with multiple functions is deprecated. ' | ||
+ 'This behavior is going to be dropped on v0.13.0. Use `call` instead.'); | ||
let nextHandler = null; | ||
@@ -75,3 +72,3 @@ return chain.reverse().map(h => { | ||
return false; | ||
return this.fallbackRoute ?? false; | ||
} | ||
@@ -85,3 +82,7 @@ | ||
input.next = handler.next | ||
? () => runHandler(input, handler.next, done) | ||
? () => { | ||
input.log.warn('`next()` is deprecated. ' | ||
+ 'This parameter will be dropped on v0.13.0. Use `call` instead.'); | ||
return runHandler(input, handler.next, done) | ||
} | ||
: () => done(); | ||
@@ -107,2 +108,3 @@ | ||
// this => app | ||
this.log.warn('`fork` is deprecated. This method will be dropped on v0.13.0.'); | ||
return new Promise((resolve, reject) => { | ||
@@ -115,2 +117,5 @@ func = normalizeHandler(func.bind(this)); | ||
function buildHook(hookName, ...chain){ | ||
chain.length > 1 && | ||
this.context.log.warn('`pre()` and `pos()` hooks are deprecated. ' | ||
+ 'Those methods will be dropped on v0.13.0. Use `call` instead.'); | ||
let stack = buildStack(this.context, chain); | ||
@@ -128,2 +133,3 @@ this[hookName] = stack[0]; | ||
this.context = context; | ||
this.fallbackRoute = null; | ||
@@ -137,4 +143,9 @@ // Generate HTTP verb shortcut route methods | ||
proxy.all = (...chain) => METHODS.forEach(m => | ||
this.addEndpoint(m.toLowerCase(), '(.*)', ...chain)); | ||
proxy.all = (...chain) => { | ||
assert(!this.fallbackRoute, new Error('Route for \'ALL\' is already defined')); | ||
assert(chain.length > 0, new Error('Route is empty at \'ALL\'')); | ||
let stack = buildStack(this.context, chain); | ||
stack.slice(-1)[0].tail = true; | ||
this.fallbackRoute = stack[0]; | ||
}; | ||
@@ -176,5 +187,19 @@ proxy.pre = buildHook.bind(this, 'preHook'); | ||
const flash = new Proxy({}, { | ||
get() { | ||
app.log.warn('`flash` is deprecated. ' | ||
+ 'This parameter will be dropped on v0.13.0.'); | ||
return Reflect.get(...arguments); | ||
}, | ||
set(){ | ||
app.log.warn('`flash` is deprecated. ' | ||
+ 'This parameter will be dropped on v0.13.0.'); | ||
return Reflect.set(...arguments); | ||
} | ||
}); | ||
input = { | ||
...app.global, conf: app.conf, flash: {}, cookies: {}, headers: {}, | ||
query: {}, ...input, params, log: app.log, signedCookies: {} | ||
...app.global, conf: app.conf, flash, cookies: {}, headers: {}, | ||
query: {}, ...input, params, log: app.log, signedCookies: {}, | ||
method, path | ||
}; | ||
@@ -185,4 +210,13 @@ input.fork = fork.bind(app, input); | ||
let origReq = input.req || {}; | ||
input.req = { method, path, host: origReq.host, 'user-agent': origReq['user-agent'] }; | ||
input.req = new Proxy({ | ||
method, path, host: origReq.host, 'user-agent': origReq['user-agent'] | ||
}, { | ||
get() { | ||
app.log.warn('`req` is deprecated. ' | ||
+ 'This parameter will be dropped on v0.13.0.'); | ||
return Reflect.get(...arguments); | ||
} | ||
}); | ||
app.log.debug({ | ||
@@ -189,0 +223,0 @@ method: method, path, |
const querystring = require('querystring'); | ||
const contentType = require('content-type'); | ||
@@ -87,3 +86,3 @@ | ||
return await read.call(this, raw => | ||
querystring.parse(raw.toString(this.textCharset))); | ||
Object.fromEntries(new URLSearchParams(raw.toString(this.textCharset)).entries())); | ||
} | ||
@@ -90,0 +89,0 @@ |
const cookie = require('cookie'); | ||
const querystring = require('querystring'); | ||
const normalizePath = p => (p.slice(-1) == '/' ? p.slice(0, -1) : p) || '/'; | ||
@@ -14,8 +13,7 @@ | ||
let [ path, query ] = req.url.split('?'); | ||
req.path = normalizePath(path); | ||
req.cookies = cookie.parse(req.headers.cookie || ''); | ||
req.query = querystring.parse(query); | ||
await this._api.trigger(req.method, req.path, { | ||
query: req.query, req, res, headers: req.headers, cookies: req.cookies | ||
await this._api.trigger(req.method, normalizePath(path), { | ||
req, res, headers: req.headers, | ||
query: Object.fromEntries(new URLSearchParams(query).entries()), | ||
cookies: cookie.parse(req.headers.cookie || '') | ||
}); | ||
@@ -22,0 +20,0 @@ } |
@@ -61,3 +61,2 @@ const | ||
// TODO remove _alwaysRebuildAPI on 0.13.0 | ||
this._alwaysRebuildAPI = opts.alwaysRebuildAPI || false; | ||
@@ -72,2 +71,6 @@ | ||
opts.alwaysRebuildAPI && | ||
this.log.warn('`alwaysRebuildAPI` is deprecated. ' | ||
+ 'This parameter will be dropped on v0.13.0.'); | ||
if(!this._alwaysRebuildAPI) | ||
@@ -74,0 +77,0 @@ this._api = new API(this, this._apiSpec); |
{ | ||
"name": "nodecaf", | ||
"version": "0.12.4", | ||
"version": "0.12.5", | ||
"description": "Nodecaf is a light framework for developing RESTful Apps in a quick and convenient manner.", | ||
"main": "lib/main.js", | ||
"types": "./lib/main.d.ts", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "test": "mocha -b --no-diff test/*.js", |
@@ -55,3 +55,3 @@ # [Nodecaf](https://gitlab.com/GCSBOSS/nodecaf) | ||
```js | ||
module.exports = function({ post, get, del, head, patch, put }){ | ||
module.exports = function({ post, get, del, head, patch, put, all }){ | ||
@@ -62,2 +62,5 @@ // Define routes and a list of middleware functions (async or regular no matter). | ||
// ... | ||
// This route runs whenever there is no other path match | ||
all(Foo.atLast) | ||
}; | ||
@@ -174,4 +177,4 @@ ``` | ||
- `req`, `res`, `next`: The good old parameters used regularly in middleware-like frameworks. | ||
- `query`, `parameters`, `body`, `headers`: Shortcuts to the homonymous properties of `req`. | ||
They contain respectively the query string, the URL parameters, and the request | ||
- `method`, `path`, `query`, `parameters`, `body`, `headers`: Shortcuts to the homonymous properties of `req`. | ||
They contain respectively the HTTP method, request URL path, query string, the URL parameters, and the request | ||
body data. | ||
@@ -178,0 +181,0 @@ - `flash`: Is an object where you can store arbitrary values. Keys inserted in this |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51396
10
864
479