bigriver
Advanced tools
Comparing version 1.1.3 to 1.1.4
/// <reference types="node" /> | ||
import { FastifyServerOptions } from 'fastify'; | ||
import { Router } from './router'; | ||
declare type RequestState = Record<string, any>; | ||
declare module 'fastify' { | ||
@@ -9,3 +10,2 @@ interface FastifyRequest { | ||
} | ||
export declare type RequestState = Record<string, any>; | ||
export declare const useApp: ({ routers, cors, logger, caseSensitive, ignoreTrailingSlash, ...fastifyOptions }?: { | ||
@@ -31,1 +31,2 @@ routers?: { | ||
}) => import("fastify").FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyLoggerInstance> & PromiseLike<import("fastify").FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyLoggerInstance>>; | ||
export {}; |
{ | ||
"name": "bigriver", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "A fast well-typed back-end prototyping framework", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -129,4 +129,4 @@ # Bigriver | ||
}, | ||
handler: async (req, res) => { | ||
const { user } = res.context.config | ||
handler: async req => { | ||
const { user } = req.state | ||
const { direction, type } = req.query | ||
@@ -158,3 +158,3 @@ | ||
```typescript | ||
export const AuthGuard: Middleware = async (req, res) => { | ||
export const AuthGuard: Middleware = async req => { | ||
if (!req.headers.authorization) { | ||
@@ -167,11 +167,11 @@ throw new Unauthorized() | ||
res.context.config.user = result | ||
req.state = result | ||
} | ||
``` | ||
By default, we don't have a key called "user" under our context config. Therefore, it's important to create a type file for typescript to recoginize it. You may simply create a type.d.ts in your source code directory. | ||
By default, we don't have a key called "user" under our request state. Therefore, it's important to create a type file for typescript to recoginize it. You may simply create a type.d.ts in your source code directory. | ||
```typescript | ||
declare module 'bigriver' { | ||
interface ContextConfig { | ||
declare module 'fastify' { | ||
interface RequestState { | ||
user: { | ||
@@ -185,3 +185,3 @@ _id: string | ||
By modify the context config, you will be allowed to get them in your route handler like this: | ||
By modify the request state, you will be allowed to get them in your route handler like this: | ||
@@ -191,4 +191,4 @@ ```typescript | ||
schema: {}, | ||
handler: async (req, res) => { | ||
const { user } = res.context.config | ||
handler: async req => { | ||
const { user } = req.state | ||
// ... | ||
@@ -195,0 +195,0 @@ }, |
@@ -5,2 +5,4 @@ import fastify, { FastifyRequest, FastifyServerOptions } from 'fastify' | ||
type RequestState = Record<string, any> | ||
declare module 'fastify' { | ||
@@ -12,4 +14,2 @@ interface FastifyRequest { | ||
export type RequestState = Record<string, any> | ||
export const useApp = ({ | ||
@@ -16,0 +16,0 @@ routers = [], |
Sorry, the diff of this file is not supported yet
1579
187066