Conversation
|
Does it have a performance impact? |
It's going to be tiny/hard to measure. Essentially it's the cost of @StarpTech please check the docs. |
|
Would it make sense to async function handler (req, reply) {
const someResult = await anAsyncFunction(req.body)
if (someResult.error) {
return reply.code(500).send({ error: someResult.error })
}
return reply.send({ success: 'is-you' })
} |
|
Yes, support full reply chaining in that case would be nice. |
| <a name="then"></a> | ||
| ### .then(fullfilled, rejected) | ||
|
|
||
| As the name suggests, `reply.then()` makes `Reply` awaitable. |
There was a problem hiding this comment.
I'd refer to some source which explains "await able". We can also use it with promises only.
|
@StarpTech @delvedor updated |
Co-Authored-By: James Sumners <[email protected]>
| reply.send(processed) | ||
| }) | ||
| await reply | ||
| }) |
There was a problem hiding this comment.
Can you make this example a little bit more clear? Where is processed coming from?
* Make reply a thenable * Docs and more tests * docs and test * reply.send() returns reply * Apply suggestions from code review Co-Authored-By: James Sumners <[email protected]> * Clearer examples * Fix Node 6
* add tap into greenkeeper ignore list (#1643) * Added `fastify-decorators` to Ecosystem.md (#1645) * Fix typo in azure-pipelines.yml (#1649) Windows + Yarn section name was `Windows_yarm` * offboarding steps (#1646) * fix(types): fix register options (#1644) * chore(package): update flatstr to version 1.0.12 (#1653) * Catches onRoute hooks errors (#1651) * Catches onRoute hooks errors * Fixes typo * Removes unneeded test * add example repo link (#1648) * chore(package): update send to version 0.17.0 (#1627) * Emit warning synchronously (#1657) Fixes #1656 * Make some spelling and grammar corrections to TS.md (#1640) * internal: moved route code (#1625) * docs(reply): clarify settings headers (#1642) * Bumped v2.4.0 * Add .git folder to NPM ignore (#1663) * Add .git folder to NPM ignore * Update .npmignore Co-Authored-By: Manuel Spigolon <[email protected]> * Bumped v2.4.1 * Adds defaults to TS generics definitions (#1669) * Update node types, typescript, and fix broken test (#1681) * Add RBAC plugin to Ecosystem (#1692) * Removes double call to afterRouteAdded when ignoreTrailingSlash === true (#1675) * Removes double call to afterRouteAdded when ignoreTrailingSlash === true * Adds explaining comment when adding a prefixed plugin * docs: fix req.body inside logger req (#1695) * Alias schema.query to schema.querystring (#1690) (#1694) * docs: fix typos (#1701) * chore: greenkeeper ignore autocannon (#1696) * fix: use reply instead of original res (#1704) * Added case sensitive option to definition file. (#1691) * Added case sensitive option to definition file. * Added casSensitive Option to test * add ability to get response time on reply (#1697) * add ability to get response time on reply * feedback * Update docs/Reply.md as per suggestion Co-Authored-By: Manuel Spigolon <[email protected]> * update type of FastifyReply * add type test * Bumped v2.5.0 * feature: custom serializator (#1706) * Improve support for Fluent Schema (#1719) * Improve support for Fluent Schema * Updated test * Updated docs * Avoid code duplication * allow nullable option in schemas #1709 (#1711) * Clarify that user-provided data relates to the schemas (#1722) * Bumped v2.6.0 * docs(Ecosystem): Add plugin community fastify-amqp (#1724) * docs(Ecosystem): Add plugin community fastify-amqp * docs(Ecosystem): Change order of fastify amqp * docs(Ecosystem): Removed fastify-nuxt community package (#1725) The package not found more. * docs: move Trivikram to past collaborators (#1727) * docs(Ecosystem): Add plugin community fastify-reverse-routes (#1728) * docs: Add cls-rtracer to Ecosystem (#1731) * test: change describe for content-length.test.js (#1735) * Update Server.md (#1718) In the genReqId sention, it is mentioned in note, that the provided function for it will not be called if the "request-id" header is available. Hence, I think in the mentioned example, it should only return "i++" instead of "req.headers['request-id'] || i++"' as here the header here will not be present always. * fix typo Routes.md (#1743) * Avoid return 503 after closing fastify (#1723) * Avoid return 503 after closing fastify * Allow ECONNRESET as error code * Destroy tcp connection when http request finishes * Add flag return503OnClosing. Default true * Add docs * Add return503OnClosing to typescript definition * Rework * Update test/http2/closing.js Co-Authored-By: Manuel Spigolon <[email protected]> * Update test/http2/closing.js Co-Authored-By: Manuel Spigolon <[email protected]> * Lint code * change code examples in Reply documentation (#1751) * tap --no-esm (#1752) * docs(Hooks): Add payload inside example to prevent bugs (#1739) * Fix typo Hooks.md (#1759) * Update standard to the latest version 🚀 (#1741) * chore(package): update standard to version 13.0.1 * Fix standard * Fixed linting * docs(Ecosystem): Add fastify-no-additional-properties community plugin (#1762) * docs(Ecosystem): Add fastify-no-additional-properties community plugin * Update docs/Ecosystem.md Co-Authored-By: Manuel Spigolon <[email protected]> * security policy (#1738) * security.md * Apply suggestions from code review Co-Authored-By: James Sumners <[email protected]> * add link * add plugins notice * docs: change the `next` to `done` inside documentation (#1756) * docs(Plugins): Fix typo (#1764) * Fix bug regarding Joi schemas (#1768) * Bumped v2.7.0 * docs: simplify serverless usage with aws-lambda-fastify (#1748) * better typing for headers object (#1775) * better typing for headers object * Update fastify.d.ts Co-Authored-By: Tomas Della Vedova <[email protected]> * Ensure we are not running the handler if reply.sent is true (#1778) Fixes #1733 Fixes #1776 * Added Google Cloud Run docs (#1770) * Added Google Cloud Run docs * Update docs/Serverless.md Co-Authored-By: Manuel Spigolon <[email protected]> * Update docs/Serverless.md Co-Authored-By: Manuel Spigolon <[email protected]> * Updated docs * Bumped v2.7.1 * docs(Serverless): add missing punctuation marks (#1783) * Add toStrinTag to errors (#1785) * [ts] Add `handler` to `RouteShorthandOptions` (#1788) * [ts] Add `handler` to `RouteShorthandOptions` * [ts] make `handler` prop optional (incase already defined in opts) * update tests * typo: typescript-server.ts (#1791) * Add request property to reply documentation (#1792) * typescript: add incoming request property to fastify reply type * docs(reply): add request to list of exposed reply properties (#1734) * Use .isFluentSchema instead of symbol to check for fluent-schema (#1794) * Use .isFluentSchema instead of symbol to check for fluent-schema * Add back symbol check for backcompat * fix inverted if in serverless example (#1797) in one example of the serverless documentation: (require.main === module) was inverted * Ensure that header properties are not duplicated in schema (#1806) * docs(Hooks): Add each Hook to a title (#1801) * Docs(typescript) and other typos (#1811) * docs(TypeScript): fix order of parameters according to type definitions https://github.com/andriyor/fastify/blob/124e7eea7af4048b008abf9c495bb581ec25061b/fastify.d.ts#L364 * docs: fix typos * docs(Hooks): (#1810) 1. move L7 to L33, for it is a description for Request/Reply hooks. 2. change the number of Request/Reply hooks from seven to eight. 3. add a description for different types of hooks in L7. * Update standard (#1816) * chore(package): update standard to version 14.0.0 * fix linting errors for standard@14 * add plugin for autogenerate crud route in Ecosystem (#1813) * chore(package): update @typescript-eslint/parser to version 2.0.0 (#1799) * Improve default 404 route (#1826) * Schema build error (#1808) * add route when build schema fails * remove file * adding tests * bubble up FastifyError * prefix test * removed file * Update Ecosystem.md (#1827) Plugin to expose REST API for Mongoose MongoDB connection. * fix: premature close test (#1833) There was an incorrect test count on the premature close tests where it never actually tested whether 'close' was emitted. `'close'` is actually not emitted and to fix these test we need to increment the test count and instead listen for `'aborted'`. * Added Zeit Now docs (#1824) * greenkeeper ignore @typescript-eslint/eslint-plugin (#1835) * Bumped v2.8.0 * Improving Getting Started documentation (#1837) * feat - Implement pluginName (#1836) * imlement pluginName * remove newline, improve test headline * add docs, build plugin name chain * improve docs * fix order * add test * Update docs/Server.md Co-Authored-By: Manuel Spigolon <[email protected]> * improve tests * feature: add onResponse hook in route declaration (#1838) * Fix eslint "no-misused-promises" error in hooks (#1843) * fix eslint "no-misused-promises" error in hooks * test hook async function typescript * Update Validation-and-Serialization.md (#1846) * docs(Reply): fix Errors (#1848) add 'code' to error struct * First batch of documentation fixes (#1850) * docs(Benchmarking): Improve grammar * docs(ContentTypeParser): Improve grammar * docs(Decorators): Improve grammar * docs(Errors): Improve grammar * docs(FluentSchema): Improve grammar * docs(GettingStarted): Improve grammar * docs(Hooks): Improve grammar * docs(HTTP2): Improve grammar * docs(Logging): Improve grammar * docs(Middleware): Improve grammar * docs(PluginsGuide): Improve grammar * Update middleware docs link * Always put Content-Type in backticks * docs(Hooks): Fix typo * add FastifyReply#removeHeader method to fastify.d.ts (#1849) * add FastifyReply#removeHeader method to fastify.d.ts * add test * Update test/types/index.ts Co-Authored-By: Manuel Spigolon <[email protected]> * randomize file name in test (#1856) To avoid side effects from other processes, avoid using a predictable file name for the socket in the OS tmp directory. * Move Nathan Woltman to Past Collaborators (#1857) * add github workflow for CI and website, (#1853) add github workflow for CI and website,remove travis * possible fixes (#1861) * possible fixes * generate lcov file for coveralls * run tests only one time * dont generate html report * fix (#1862) * Fix/pkg manager ci (#1863) run script with package manager, install eslint as dev dep to avoid typescript-eslint error * install yarn and pnpm in the host env (#1865) * install yarn and pnpm in the host env * use pnpm to run test * fix typo * Rules to contributing to plugins (#1842) * Make reply a thenable (#1869) * Make reply a thenable * Docs and more tests * docs and test * reply.send() returns reply * Apply suggestions from code review Co-Authored-By: James Sumners <[email protected]> * Clearer examples * Fix Node 6 * docs(Plugins): removed prefix from list with fastify-plugin (#1819) * docs(Plugins): removed prefix from list with fastify-plugin * docs(Plugins): add notice for logLevel and prefix with fastify-plugin * tests: add test to ignore prefix * fix: removed async to support node6 * Add SerayaEryn to team list (#1867) * Add SerayaEryn to team list * Add SerayaEryn to package.json * Don't change resolved schema (#1872) * Don't change resolved schema Fixes #1871 * Restore version * Fix Plugin type in fastify.d.ts (#1841) According to avvio (https://github.com/mcollina/avvio/blob/3a386683994bfb274355edbb0d7d892e0e066e9a/plugin.js#L89) the `register()` function expects plugins to be either synchronous functions, asynchronous functions with a `callback` argument or asynchronous functions that return promises. * fix(package): update tiny-lru to version 7.0.0 (#1874) * feature: schema resolver (#1858) * quick and dirty schema resolver * add test for body * add not staged edits * add encapsulation test * add mandatory schema compiler for resolver * add docs * Update docs/Validation-and-Serialization.md Co-Authored-By: James Sumners <[email protected]> * Fix warning for onError hook (#1876) * Fix warning for onError hook The onError hook has 3 parameters (request, reply, error) and it's currently triggering a warning saying that it has too many arguments. This change adds `onError` the same condition branch as `onSend` and `preSerialization`. * Update Server.md (#1878) fix link: Middlewares.md -> Middleware.md * Bumped v2.9.0. * fix schema resolver for plain id (#1882) * fix schema resolver for plain id * update fast-json-stringify * add test on response schema * fix ajv compile error * add typings * chore(package): update concurrently to version 5.0.0 (#1886) * greenkeeper do not update lolex (#1887) * add .headers to reply docs (#1890) * feature: reply statusCode (#1892) * Bumped v2.10.0 * Test: After can access to decorations registered into plugin (#1891) * test: after can access to decorations registered into plugin * Fix identation * Fix identation #2 * chore(package): update h2url to version 0.2.0 (#1902) * Add type definition for genReqId option (#1899) * add missing fluent schema link (#1903) * Updates fastify-multer repository (#1904) * Add Node v13 to CI (#1912) * adds fastify-https-redirect to ecosystem (#1911) * Added support for onConstructorPoisoning (#1910) * Added support for onConstructorPoisoning * Updated dependencies * Updated docs * Updated test * Updated type definitions * Add log serializer (#1901) * feat: add logSerializer * tests(logSerializer): add test for logSerializer by route * test(logger): add tests for logSerializer * test(logger): fix lint errors * docs(Routes): adjust description of LogSerializer * fix(logSerializer): adjust prevent for 404 route * refactor(route): adjust childLogger with conditional * refactor(logSerializer): changed logSerializer to logSerializers * fix(router): refactor logSerializer to work in node 6 * tests(logSerializers): add more test to check override by route * tests(logSerializers): add test to check inherit from contexts * refactor: adjust prevent memory alocation unecessary * Added fastify-qs plugin (#1906) * Handle invalid url components (#1888) * Fix #1884 * Updated test * Update Actions to use latest versions of all OS's (#1907) * less coverage messages (#1918) * chore(package): update form-data to version 3.0.0 (#1923) * Update documentation to fix anchors for Hooks (#1928) * Added missing types for Server Options (#1922) * Added missing typescript types * Added http2 server factory test * Fix/1932 Add version field to the route options (#1933) * Update abstract-logging to v2 (#1941) * Update Routes.md (#1942) * Add fastify-errors-properties plugin to Ecosystem (#1944) * Add fastify-errors-properties plugin * Put plugin in the right order. * Add fastify-auth0-verify to Ecosystem. (#1947) * chore(package): update fluent-schema to version 0.8.0 (#1950) * Added note about OpenJS Foundation (#1948) * Update onRoute documentation for plugin authors. (#1956) * docs: fix example onRoute with preSerialization (#1959) * feature: Ajv custom options (#1946) * Update package.json Co-Authored-By: Ethan Arrowood <[email protected]> Co-authored-by: Sandro Martini <[email protected]> Co-authored-by: Andrey Chalkin <[email protected]> Co-authored-by: Daniil Kolesnik <[email protected]> Co-authored-by: Alexander Kureniov <[email protected]> Co-authored-by: Maksim Sinik <[email protected]> Co-authored-by: greenkeeper[bot] <23040076+greenkeeper[bot]@users.noreply.github.com> Co-authored-by: Matteo Collina <[email protected]> Co-authored-by: Alex Otten <[email protected]> Co-authored-by: Okan Sahin <[email protected]> Co-authored-by: Davlat Shavkatov <[email protected]> Co-authored-by: Tomas Della Vedova <[email protected]> Co-authored-by: Ethan Arrowood <[email protected]> Co-authored-by: Rafael Gonzaga <[email protected]> Co-authored-by: Raghav Manikandan <[email protected]> Co-authored-by: 小菜 <[email protected]> Co-authored-by: Vincenzo Chianese <[email protected]> Co-authored-by: hhwang39 <[email protected]> Co-authored-by: Glen Keane <[email protected]> Co-authored-by: Adriano Raiano <[email protected]> Co-authored-by: Trivikram Kamat <[email protected]> Co-authored-by: Dmitrii <[email protected]> Co-authored-by: Andrey Pechkurov <[email protected]> Co-authored-by: Abhishek Nigam <[email protected]> Co-authored-by: Chris Hawkes <[email protected]> Co-authored-by: Tommaso Allevi <[email protected]> Co-authored-by: kharandziuk <[email protected]> Co-authored-by: Zoron <[email protected]> Co-authored-by: Giacomo Gregoletto <[email protected]> Co-authored-by: James Sumners <[email protected]> Co-authored-by: Paris Holley <[email protected]> Co-authored-by: Jinesh Shah <[email protected]> Co-authored-by: Toan Nguyen <[email protected]> Co-authored-by: Tobias Mühl <[email protected]> Co-authored-by: Francis Brito <[email protected]> Co-authored-by: kivi <[email protected]> Co-authored-by: Jemar Jones <[email protected]> Co-authored-by: Андрій Орєхов <[email protected]> Co-authored-by: Denis Fäcke <[email protected]> Co-authored-by: Marco Ferraioli <[email protected]> Co-authored-by: Jeka Kiselyov <[email protected]> Co-authored-by: Robert Nagy <[email protected]> Co-authored-by: Ryan Albon <[email protected]> Co-authored-by: Dustin Deus <[email protected]> Co-authored-by: Michael Chris Lopez <[email protected]> Co-authored-by: Chia Wei Ong <[email protected]> Co-authored-by: lw <[email protected]> Co-authored-by: Toru Nagashima <[email protected]> Co-authored-by: Rich Trott <[email protected]> Co-authored-by: Nathan Woltman <[email protected]> Co-authored-by: Alik Send <[email protected]> Co-authored-by: Johannes Ewald <[email protected]> Co-authored-by: Boris D'Amato <[email protected]> Co-authored-by: Tom Andrews <[email protected]> Co-authored-by: Thomas Vogel <[email protected]> Co-authored-by: Vano Devium <[email protected]> Co-authored-by: Kayla Ngan <[email protected]> Co-authored-by: Kevin Rambaud <[email protected]> Co-authored-by: Nilesh Mali <[email protected]> Co-authored-by: Marc Fisher <[email protected]> Co-authored-by: Shogun <[email protected]> Co-authored-by: De Oliveira Tristan <[email protected]>
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Fixes #1864
Checklist
npm run testandnpm run benchmark