Comparing version 5.4.0 to 6.0.0
@@ -1,4 +0,14 @@ | ||
import {NextHandleFunction, SimpleHandleFunction} from 'connect' | ||
import * as connect from 'connect' | ||
import {FastifyPluginCallback} from 'fastify' | ||
import * as http from "http"; | ||
export interface IncomingMessageExtended { | ||
body?: any; | ||
query?: any; | ||
} | ||
type NextFunction = (err?: any) => void; | ||
type SimpleHandleFunction = (req: http.IncomingMessage & IncomingMessageExtended, res: http.ServerResponse) => void; | ||
type NextHandleFunction = (req: connect.IncomingMessage & IncomingMessageExtended, res: http.ServerResponse, next: NextFunction) => void; | ||
type Handler = SimpleHandleFunction | NextHandleFunction | ||
@@ -14,4 +24,4 @@ | ||
// Middie doesn't have options yet | ||
export interface MiddiePluginOptions { | ||
hook?: 'onRequest' | 'preParsing' | 'preValidation' | 'preHandler' | 'preSerialization' | 'onSend' | 'onResponse' | 'onTimeout' | 'onError'; | ||
} | ||
@@ -18,0 +28,0 @@ |
@@ -40,2 +40,4 @@ 'use strict' | ||
req.raw.log = req.log | ||
req.raw.body = req.body | ||
req.raw.query = req.query | ||
reply.raw.log = req.log | ||
@@ -42,0 +44,0 @@ this[kMiddie].run(req.raw, reply.raw, next) |
{ | ||
"name": "middie", | ||
"version": "5.4.0", | ||
"version": "6.0.0", | ||
"description": "Middleware engine for Fastify", | ||
@@ -38,3 +38,3 @@ "main": "index.js", | ||
"fastify": "^3.0.0", | ||
"helmet": "^4.0.0", | ||
"helmet": "^5.0.0", | ||
"pre-commit": "^1.2.2", | ||
@@ -41,0 +41,0 @@ "serve-static": "^1.14.1", |
@@ -99,2 +99,4 @@ # middie | ||
*Note you can access `req.body` from the `preValidation` lifecycle step onwards. Take a look at the [Lifecycle](https://www.fastify.io/docs/latest/Lifecycle/) documentation page to see the order of the steps.* | ||
```js | ||
@@ -101,0 +103,0 @@ const fastify = require('fastify')() |
@@ -11,10 +11,10 @@ 'use strict' | ||
test('Should enhance the Node.js core request/response objects', t => { | ||
t.plan(9) | ||
t.plan(13) | ||
const fastify = Fastify() | ||
t.teardown(fastify.close) | ||
fastify.register(middiePlugin) | ||
fastify.register(middiePlugin, { hook: 'preHandler' }) | ||
.after(() => { fastify.use(cors()) }) | ||
fastify.get('/', async (req, reply) => { | ||
fastify.post('/', async (req, reply) => { | ||
t.equal(req.raw.originalUrl, req.raw.url) | ||
@@ -25,2 +25,6 @@ t.equal(req.raw.id, req.id) | ||
t.same(req.raw.ips, req.ips) | ||
t.same(req.raw.body, req.body) | ||
t.same(req.raw.query, req.query) | ||
t.ok(req.raw.body.bar) | ||
t.ok(req.raw.query.foo) | ||
t.ok(req.raw.log) | ||
@@ -34,4 +38,6 @@ t.ok(reply.raw.log) | ||
sget({ | ||
method: 'GET', | ||
url: address | ||
method: 'POST', | ||
url: `${address}?foo=bar`, | ||
body: { bar: 'foo' }, | ||
json: true | ||
}, (err, res, data) => { | ||
@@ -44,9 +50,9 @@ t.error(err) | ||
test('Should not enhance the Node.js core request/response objects when there are no middlewares', t => { | ||
t.plan(9) | ||
t.plan(11) | ||
const fastify = Fastify() | ||
t.teardown(fastify.close) | ||
fastify.register(middiePlugin) | ||
fastify.register(middiePlugin, { hook: 'preHandler' }) | ||
fastify.get('/', async (req, reply) => { | ||
fastify.post('/', async (req, reply) => { | ||
t.equal(req.raw.originalUrl, undefined) | ||
@@ -57,2 +63,4 @@ t.equal(req.raw.id, undefined) | ||
t.equal(req.raw.ips, undefined) | ||
t.same(req.raw.body, undefined) | ||
t.same(req.raw.query, undefined) | ||
t.notOk(req.raw.log) | ||
@@ -66,4 +74,6 @@ t.notOk(reply.raw.log) | ||
sget({ | ||
method: 'GET', | ||
url: address | ||
method: 'POST', | ||
url: `${address}?foo=bar`, | ||
body: { bar: 'foo' }, | ||
json: true | ||
}, (err, res, data) => { | ||
@@ -70,0 +80,0 @@ t.error(err) |
import fastify from "fastify"; | ||
import middiePlugin, {MiddiePluginOptions} from ".."; | ||
import { expectAssignable } from "tsd"; | ||
import middiePlugin, {MiddiePluginOptions, IncomingMessageExtended} from ".."; | ||
import { expectAssignable, expectType } from "tsd"; | ||
@@ -10,4 +10,10 @@ const app = fastify(); | ||
expectAssignable<IncomingMessageExtended>({ body: { foo: 'bar' }, query: { bar: 'foo' }}) | ||
expectAssignable<IncomingMessageExtended>({}) | ||
app.use('/', (_req, _res, next) => { | ||
expectType<any | undefined>(_req.body) | ||
expectType<any | undefined>(_req.query) | ||
next() | ||
}) |
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
61176
1909
253