Comparing version 4.10.2 to 4.11.0
@@ -223,2 +223,6 @@ <h1 align="center">Fastify</h1> | ||
Plugin for interacting with Appwrite server. | ||
- [`fastify-at-mysql`](https://github.com/mateonunez/fastify-at-mysql) Fastify | ||
MySQL plugin with auto SQL injection attack prevention. | ||
- [`fastify-at-postgres`](https://github.com/mateonunez/fastify-at-postgres) Fastify | ||
Postgres plugin with auto SQL injection attack prevention. | ||
- [`fastify-auth0-verify`](https://github.com/nearform/fastify-auth0-verify): | ||
@@ -391,2 +395,5 @@ Auth0 verification plugin for Fastify, internally uses | ||
[lured](https://github.com/enobufs/lured). | ||
- [`fastify-lyra`](https://github.com/mateonunez/fastify-lyra) | ||
A plugin to implement [Lyra](https://github.com/LyraSearch/lyra) search engine | ||
on Fastify. | ||
- [`fastify-mailer`](https://github.com/coopflow/fastify-mailer) Plugin to | ||
@@ -570,2 +577,4 @@ initialize and encapsulate [Nodemailer](https://nodemailer.com)'s transporters | ||
Fastify plugin to work with TypeORM. | ||
- [`fastify-user-agent`](https://github.com/Eomm/fastify-user-agent) parses your | ||
request's `user-agent` header. | ||
- [`fastify-vhost`](https://github.com/patrickpissurno/fastify-vhost) Proxy | ||
@@ -572,0 +581,0 @@ subdomain HTTP requests to another server (useful if you want to point |
@@ -115,2 +115,5 @@ <h1 align="center">Fastify</h1> | ||
reply.status(500).send({ ok: false }) | ||
} else { | ||
// fastify will use parent error handler to handle this | ||
reply.send(error) | ||
} | ||
@@ -386,2 +389,2 @@ }) | ||
Plugin did not start in time. Default timeout (in millis): `10000` | ||
Plugin did not start in time. Default timeout (in millis): `10000` |
@@ -677,2 +677,11 @@ <h1 align="center">Fastify</h1> | ||
``` | ||
When using async-await you will need to return or await the reply object: | ||
```js | ||
fastify.get('/streams', async function (request, reply) { | ||
const fs = require('fs') | ||
const stream = fs.createReadStream('some-file', 'utf8') | ||
reply.header('Content-Type', 'application/octet-stream') | ||
return reply.send(stream) | ||
}) | ||
``` | ||
@@ -693,2 +702,12 @@ #### Buffers | ||
When using async-await you will need to return or await the reply object: | ||
```js | ||
const fs = require('fs') | ||
fastify.get('/streams', async function (request, reply) { | ||
fs.readFile('some-file', (err, fileBuffer) => { | ||
reply.send(err || fileBuffer) | ||
}) | ||
return reply | ||
}) | ||
``` | ||
#### Errors | ||
@@ -695,0 +714,0 @@ <a id="errors"></a> |
@@ -1014,2 +1014,5 @@ <h1 align="center">Fastify</h1> | ||
**Notice**: this method is deprecated and should be removed in the next Fastify | ||
major version. | ||
The `defaultRoute` handler handles requests that do not match any URL specified | ||
@@ -1027,10 +1030,21 @@ by your Fastify application. This defaults to the 404 handler, but can be | ||
**Note**: The default 404 handler, or one set using `setNotFoundHandler`, will | ||
never trigger if the default route is overridden. This sets the handler for the | ||
**Notice**: this method is deprecated and should be removed in the next Fastify | ||
major version. Please, consider to use `setNotFoundHandler` or a wildcard | ||
matching route. | ||
The default 404 handler, or one set using `setNotFoundHandler`, will | ||
never trigger if the default route is overridden. This sets the handler for the | ||
Fastify application, not just the current instance context. Use | ||
[setNotFoundHandler](#setnotfoundhandler) if you want to customize 404 handling | ||
instead. Method to set the `defaultRoute` for the server: | ||
instead. | ||
This method sets the `defaultRoute` for the server. Note that, its purpose is | ||
to interact with the underlying raw requests. Unlike other Fastify handlers, the | ||
arguments received are of type [RawRequest](./TypeScript.md#rawrequest) and | ||
[RawReply](./TypeScript.md#rawreply) respectively. | ||
```js | ||
const defaultRoute = function (req, res) { | ||
// req = RawRequest | ||
// res = RawReply | ||
res.end('hello world') | ||
@@ -1675,3 +1689,3 @@ } | ||
```js | ||
fastify.addContentTypeParser('text/json', { asString: true }, fastify.defaultTextParser()) | ||
fastify.addContentTypeParser('text/json', { asString: true }, fastify.defaultTextParser) | ||
``` | ||
@@ -1678,0 +1692,0 @@ |
'use strict' | ||
const VERSION = '4.10.2' | ||
const VERSION = '4.11.0' | ||
@@ -5,0 +5,0 @@ const Avvio = require('avvio') |
@@ -73,2 +73,3 @@ 'use strict' | ||
} else { | ||
contentType.isEssence = contentType.source.indexOf(';') === -1 | ||
this.parserRegExpList.unshift(contentType) | ||
@@ -393,3 +394,3 @@ } | ||
function compareRegExpContentType (contentType, essenceMIMEType, regexp) { | ||
if (regexp.source.indexOf(';') === -1) { | ||
if (regexp.isEssence) { | ||
// we do essence check | ||
@@ -396,0 +397,0 @@ return regexp.test(essenceMIMEType) |
@@ -92,5 +92,7 @@ 'use strict' | ||
getDefaultRoute: function () { | ||
warning.emit('FSTDEP014') | ||
return router.defaultRoute | ||
}, | ||
setDefaultRoute: function (defaultRoute) { | ||
warning.emit('FSTDEP014') | ||
if (typeof defaultRoute !== 'function') { | ||
@@ -97,0 +99,0 @@ throw new FST_ERR_DEFAULT_ROUTE_INVALID_TYPE() |
@@ -28,2 +28,4 @@ 'use strict' | ||
warning.create('FastifyDeprecation', 'FSTDEP014', 'You are trying to set/access the default route. This property is deprecated. Please, use setNotFoundHandler if you want to custom a 404 handler or the wildcard (*) to match all routes.') | ||
module.exports = warning |
@@ -38,3 +38,9 @@ 'use strict' | ||
reply[kReplyIsError] = true | ||
reply.send(err) | ||
// try-catch allow to re-throw error in error handler for async handler | ||
try { | ||
reply.send(err) | ||
} catch (err) { | ||
reply.send(err) | ||
} | ||
}) | ||
@@ -41,0 +47,0 @@ } |
{ | ||
"name": "fastify", | ||
"version": "4.10.2", | ||
"version": "4.11.0", | ||
"description": "Fast and low overhead web framework, for Node.js", | ||
@@ -167,3 +167,3 @@ "main": "fastify.js", | ||
"tap": "^16.3.0", | ||
"tsd": "^0.24.1", | ||
"tsd": "^0.25.0", | ||
"typescript": "^4.8.3", | ||
@@ -170,0 +170,0 @@ "undici": "^5.10.0", |
@@ -292,4 +292,2 @@ <div align="center"> <a href="https://fastify.io/"> | ||
<https://twitter.com/allevitommaso>, <https://www.npmjs.com/~allevo> | ||
* [__Ethan Arrowood__](https://github.com/Ethan-Arrowood/), | ||
<https://twitter.com/arrowoodtech>, <https://www.npmjs.com/~ethan_arrowood> | ||
* [__Harry Brundage__](https://github.com/airhorns/), | ||
@@ -366,2 +364,4 @@ <https://twitter.com/harrybrundage>, <https://www.npmjs.com/~airhorns> | ||
<https://twitter.com/NathanWoltman>, <https://www.npmjs.com/~nwoltman> | ||
* [__Ethan Arrowood__](https://github.com/Ethan-Arrowood/), | ||
<https://twitter.com/arrowoodtech>, <https://www.npmjs.com/~ethan_arrowood> | ||
@@ -368,0 +368,0 @@ ## Hosted by |
@@ -39,3 +39,3 @@ 'use strict' | ||
const isV19plus = semver.satisfies(process.version, '>= v19.0.0') | ||
const isV19plus = semver.gte(process.version, '19.0.0') | ||
test('Should not return 503 while closing - pipelining - return503OnClosing: false, skip Node >= v19.x', { skip: isV19plus }, async t => { | ||
@@ -42,0 +42,0 @@ const fastify = Fastify({ |
@@ -206,3 +206,3 @@ 'use strict' | ||
const isV19plus = semver.satisfies(process.version, '>= v19.0.0') | ||
const isV19plus = semver.gte(process.version, '19.0.0') | ||
t.test('Current opened connection should continue to work after closing and return "connection: close" header - return503OnClosing: false, skip Node >= v19.x', { skip: isV19plus }, t => { | ||
@@ -209,0 +209,0 @@ const fastify = Fastify({ |
@@ -6,3 +6,48 @@ 'use strict' | ||
const Fastify = require('..') | ||
const warning = require('../lib/warnings') | ||
// Silence the standard warning logs. We will test the messages explicitly. | ||
process.removeAllListeners('warning') | ||
test('setDefaultRoute should emit a deprecation warning', t => { | ||
t.plan(2) | ||
const fastify = Fastify() | ||
const defaultRoute = (req, res) => { | ||
res.end('hello from defaultRoute') | ||
} | ||
process.on('warning', onWarning) | ||
function onWarning (warning) { | ||
t.equal(warning.name, 'FastifyDeprecation') | ||
t.equal(warning.code, 'FSTDEP014') | ||
} | ||
t.teardown(() => { | ||
process.removeListener('warning', onWarning) | ||
warning.emitted.set('FSTDEP014', false) | ||
}) | ||
fastify.setDefaultRoute(defaultRoute) | ||
}) | ||
test('getDefaultRoute should emit a deprecation warning', t => { | ||
t.plan(2) | ||
const fastify = Fastify() | ||
process.on('warning', onWarning) | ||
function onWarning (warning) { | ||
t.equal(warning.name, 'FastifyDeprecation') | ||
t.equal(warning.code, 'FSTDEP014') | ||
} | ||
t.teardown(() => { | ||
process.removeListener('warning', onWarning) | ||
warning.emitted.set('FSTDEP014', false) | ||
}) | ||
fastify.getDefaultRoute() | ||
}) | ||
test('should fail if defaultRoute is not a function', t => { | ||
@@ -9,0 +54,0 @@ t.plan(1) |
@@ -517,2 +517,30 @@ 'use strict' | ||
// Refs: https://github.com/fastify/fastify/pull/4484#issuecomment-1367301750 | ||
test('allow re-thrown error to default error handler when route handler is async and error handler is sync', t => { | ||
t.plan(4) | ||
const fastify = Fastify() | ||
fastify.setErrorHandler(function (error) { | ||
t.equal(error.message, 'kaboom') | ||
throw Error('kabong') | ||
}) | ||
fastify.get('/', async function () { | ||
throw Error('kaboom') | ||
}) | ||
fastify.inject({ | ||
url: '/', | ||
method: 'GET' | ||
}, (err, res) => { | ||
t.error(err) | ||
t.equal(res.statusCode, 500) | ||
t.same(JSON.parse(res.payload), { | ||
error: statusCodes['500'], | ||
message: 'kabong', | ||
statusCode: 500 | ||
}) | ||
}) | ||
}) | ||
// Issue 2078 https://github.com/fastify/fastify/issues/2078 | ||
@@ -519,0 +547,0 @@ // Supported error code list: http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
@@ -126,2 +126,17 @@ import { expectDeprecated, expectError, expectType } from 'tsd' | ||
const serverAutoInferredSerializerResponseObjectOption = fastify({ | ||
logger: { | ||
serializers: { | ||
res (ServerResponse) { | ||
expectType<FastifyReply>(ServerResponse) | ||
return { | ||
status: '200' | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
expectType<FastifyBaseLogger>(serverAutoInferredSerializerResponseObjectOption.log) | ||
const serverAutoInferredSerializerObjectOption = fastify({ | ||
@@ -128,0 +143,0 @@ logger: { |
@@ -104,1 +104,44 @@ import { expectAssignable, expectError, expectType } from 'tsd' | ||
})) | ||
// With Type Provider and logger | ||
const customLogger = { | ||
level: 'info', | ||
info: () => { }, | ||
warn: () => { }, | ||
error: () => { }, | ||
fatal: () => { }, | ||
trace: () => { }, | ||
debug: () => { }, | ||
child: () => customLogger, | ||
silent: () => { } | ||
} | ||
const serverWithTypeProviderAndLogger = fastify({ | ||
logger: customLogger | ||
}).withTypeProvider<TestTypeProvider>() | ||
type ServerWithTypeProviderAndLogger = FastifyInstance<Server, IncomingMessage, ServerResponse, typeof customLogger, TestTypeProvider> | ||
const testPluginWithTypeProviderAndLogger: FastifyPluginCallback<TestOptions, RawServerDefault, TestTypeProvider, typeof customLogger> = function (instance, opts, done) { } | ||
const testPluginWithTypeProviderAndLoggerAsync: FastifyPluginAsync<TestOptions, RawServerDefault, TestTypeProvider, typeof customLogger> = async function (instance, opts) { } | ||
const testPluginWithTypeProviderAndLoggerWithType = (instance: ServerWithTypeProviderAndLogger, opts: FastifyPluginOptions, done: (error?: FastifyError) => void) => { } | ||
const testPluginWithTypeProviderAndLoggerWithTypeAsync = async (instance: ServerWithTypeProviderAndLogger, opts: FastifyPluginOptions) => { } | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(testPluginCallback)) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(testPluginAsync)) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(testPluginOpts)) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(testPluginOptsAsync)) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(testPluginOptsWithType)) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(testPluginOptsWithTypeAsync)) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(testPluginWithTypeProviderAndLogger)) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(testPluginWithTypeProviderAndLoggerAsync)) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(testPluginWithTypeProviderAndLoggerWithType)) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(testPluginWithTypeProviderAndLoggerWithTypeAsync)) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register((instance) => { | ||
expectAssignable<FastifyInstance>(instance) | ||
})) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register((instance: ServerWithTypeProviderAndLogger) => { | ||
expectAssignable<ServerWithTypeProviderAndLogger>(instance) | ||
})) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(async (instance) => { | ||
expectAssignable<FastifyInstance>(instance) | ||
})) | ||
expectAssignable<ServerWithTypeProviderAndLogger>(serverWithTypeProviderAndLogger.register(async (instance: ServerWithTypeProviderAndLogger) => { | ||
expectAssignable<ServerWithTypeProviderAndLogger>(instance) | ||
})) |
@@ -63,3 +63,3 @@ import { FastifyError } from '@fastify/error' | ||
res?: (res: RawReply) => { | ||
statusCode: string | number; | ||
statusCode?: string | number; | ||
[key: string]: unknown; | ||
@@ -66,0 +66,0 @@ }; |
@@ -13,4 +13,9 @@ import { FastifyInstance } from './instance' | ||
*/ | ||
export type FastifyPluginCallback<Options extends FastifyPluginOptions = Record<never, never>, Server extends RawServerBase = RawServerDefault, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> = ( | ||
instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>, FastifyBaseLogger, TypeProvider>, | ||
export type FastifyPluginCallback< | ||
Options extends FastifyPluginOptions = Record<never, never>, | ||
Server extends RawServerBase = RawServerDefault, | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
> = ( | ||
instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>, Logger, TypeProvider>, | ||
opts: Options, | ||
@@ -29,4 +34,5 @@ done: (err?: Error) => void | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
> = ( | ||
instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>, FastifyBaseLogger, TypeProvider>, | ||
instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>, Logger, TypeProvider>, | ||
opts: Options | ||
@@ -33,0 +39,0 @@ ) => Promise<void>; |
@@ -5,3 +5,3 @@ import { FastifyPluginOptions, FastifyPluginCallback, FastifyPluginAsync } from './plugin' | ||
import { RawServerBase } from './utils' | ||
import { FastifyTypeProvider, RawServerDefault } from '../fastify' | ||
import { FastifyBaseLogger, FastifyTypeProvider, RawServerDefault } from '../fastify' | ||
@@ -21,15 +21,15 @@ export interface RegisterOptions { | ||
*/ | ||
export interface FastifyRegister<T = void, RawServer extends RawServerBase = RawServerDefault, TypeProviderDefault extends FastifyTypeProvider = FastifyTypeProvider> { | ||
<Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault>( | ||
plugin: FastifyPluginCallback<Options, Server, TypeProvider>, | ||
export interface FastifyRegister<T = void, RawServer extends RawServerBase = RawServerDefault, TypeProviderDefault extends FastifyTypeProvider = FastifyTypeProvider, LoggerDefault extends FastifyBaseLogger = FastifyBaseLogger> { | ||
<Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>( | ||
plugin: FastifyPluginCallback<Options, Server, TypeProvider, Logger>, | ||
opts?: FastifyRegisterOptions<Options> | ||
): T; | ||
<Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault>( | ||
plugin: FastifyPluginAsync<Options, Server, TypeProvider>, | ||
<Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>( | ||
plugin: FastifyPluginAsync<Options, Server, TypeProvider, Logger>, | ||
opts?: FastifyRegisterOptions<Options> | ||
): T; | ||
<Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault>( | ||
plugin: FastifyPluginCallback<Options, Server, TypeProvider> | FastifyPluginAsync<Options, Server, TypeProvider> | Promise<{ default: FastifyPluginCallback<Options, Server, TypeProvider> }> | Promise<{ default: FastifyPluginAsync<Options, Server, TypeProvider> }>, | ||
<Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>( | ||
plugin: FastifyPluginCallback<Options, Server, TypeProvider, Logger> | FastifyPluginAsync<Options, Server, TypeProvider, Logger> | Promise<{ default: FastifyPluginCallback<Options, Server, TypeProvider, Logger> }> | Promise<{ default: FastifyPluginAsync<Options, Server, TypeProvider, Logger> }>, | ||
opts?: FastifyRegisterOptions<Options> | ||
): T; | ||
} |
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
2016170
48362