Repository navigation
feat: detect object-form Fastify route declarations - #34
Conversation
Signed-off-by: Bl0ck154 <36800583+Bl0ck154@users.noreply.github.com>
|
Thanks @Bl0ck154. The parsing looks good and the tests pass, but there's one thing to fix before we can merge: routes in this form that do have a sign-in check get reported as open. Health reads the check on app.post('/api/plain-guarded', { preHandler: requireAuth }, handler); // left alone, correct
app.route({ method: 'POST', url: '/api/object-prehandler', preHandler: requireAuth, handler }); // reported, wrong
app.route({ method: 'POST', url: '/api/object-onrequest', onRequest: [app.authenticate], handler }); // reported, wrong
app.route({ method: 'POST', url: '/api/object-open', handler }); // reported, correctThe wrong ones show as "Anyone could change data", and the same happens when the object spans several lines. We've just released a batch of false-alarm fixes in 0.6.2, so we can't bring this kind back. Please:
|
… neighbors Signed-off-by: Bl0ck154 <36800583+Bl0ck154@users.noreply.github.com>
Signed-off-by: Bl0ck154 <36800583+Bl0ck154@users.noreply.github.com>
|
Thanks for the sample. I updated #34 to read preHandler, onRequest and preValidation from the top level of app.route({ ... }). Nested schema fields are ignored, and a guard on one route does not carry over to the next. Added a fixture for protected, open and near-miss routes, including a multiline hook array. Merged current main; npm test: 205 passed, 1 skipped. GitHub now shows the PR as mergeable with six green checks. |
|
Brought this up to date with |
|
Updated this for the latest |
The object-form route reader only looked at receivers with fixed names, so
`const api = Fastify(); api.route({...})` lost its endpoints. It now uses the
same test as app.get(): a router this file made, or a name that reads as one.
A route object's own `url:` line was also read as a request from the server
to itself; those are dropped. Adds the test file to the tests table and a
plain-language changelog line crediting #34.
#29 made any object with method, path and a handle, handler, action, resolve or fetch key an endpoint, anywhere, so a website's list of the requests it makes ({ method, path, action: 'createOrder' }, or resolve and fetch functions) became endpoints. Now the value must be a function, read by the same tableHandler as keyed tables, and action, resolve and fetch count only in a file that serves (Bun.serve, Deno.serve, createServer, listen(port), `export default { fetch }`, a router or other routes) or beside an entry with handle or handler. Listed and Bun.serve routes use main's `table` framework, so Health and the handler docs treat them as keyed tables already were. A Fastify `app.route({ method, path, handler })` read by #34's code isn't counted again by the list reader, a route's own path line isn't a request from its own file, and Health finds the code after an Express route by the next route below it rather than the next one listed, which could be a table entry above.
|
Merged and released in 0.10.0. I also made it find route objects on routers with any name ( Update with |
Complementary to #30 and PR #31: PR #31 resolves prefixes for registered plugins, while this handles a different unsupported declaration shape, fastify.route({ method, url, handler }).
Tests: npm test (164 passed, 1 skipped). See fork PR Bl0ck154#2.