bigriver
Advanced tools
Comparing version 1.1.2 to 1.1.3
/// <reference types="node" /> | ||
import { FastifyServerOptions } from 'fastify'; | ||
import { Router } from './router'; | ||
declare module 'fastify' { | ||
interface FastifyRequest { | ||
state: RequestState; | ||
} | ||
} | ||
export declare type RequestState = Record<string, any>; | ||
export declare const useApp: ({ routers, cors, logger, caseSensitive, ignoreTrailingSlash, ...fastifyOptions }?: { | ||
@@ -5,0 +11,0 @@ routers?: { |
@@ -28,2 +28,3 @@ "use strict"; | ||
} | ||
app.decorateRequest('state', null); | ||
app.addHook('onRequest', (req, _, next) => { | ||
@@ -35,2 +36,3 @@ if (req.method === 'DELETE' || req.method == 'delete') { | ||
} | ||
req.state = {}; | ||
next(); | ||
@@ -37,0 +39,0 @@ }); |
{ | ||
"name": "bigriver", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "A fast well-typed back-end prototyping framework", | ||
@@ -26,4 +26,5 @@ "main": "dist/index.js", | ||
"@types/node": "^14.14.39", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^4.2.4" | ||
} | ||
} |
@@ -1,5 +0,13 @@ | ||
import fastify, { FastifyServerOptions } from 'fastify' | ||
import fastify, { FastifyRequest, FastifyServerOptions } from 'fastify' | ||
import fastifyCors from 'fastify-cors' | ||
import { Router } from './router' | ||
declare module 'fastify' { | ||
interface FastifyRequest { | ||
state: RequestState | ||
} | ||
} | ||
export type RequestState = Record<string, any> | ||
export const useApp = ({ | ||
@@ -36,4 +44,8 @@ routers = [], | ||
// Patch for DELETE method | ||
// Decorate request for state | ||
app.decorateRequest('state', null) | ||
// Implement onRequest hook | ||
app.addHook('onRequest', (req, _, next) => { | ||
// Patch for DELETE method | ||
if (req.method === 'DELETE' || req.method == 'delete') { | ||
@@ -45,2 +57,5 @@ if (req.headers['content-type']) { | ||
// Set initial request state | ||
req.state = {} | ||
next() | ||
@@ -47,0 +62,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
187126
1578
4