mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-06 06:19:58 +08:00
[@types/body-parser] Fix so body-parser works with connect/vanilla node.js apps. (#25115)
This commit is contained in:
committed by
Wesley Wigham
parent
0823873176
commit
211a5eb474
@@ -1,3 +1,4 @@
|
||||
import * as http from 'http';
|
||||
import express = require('express');
|
||||
import {
|
||||
json,
|
||||
@@ -13,6 +14,21 @@ app.use(raw());
|
||||
app.use(text());
|
||||
app.use(urlencoded());
|
||||
|
||||
const jsonParser = app.use(json({
|
||||
inflate: true,
|
||||
limit: '100kb',
|
||||
type: 'application/*',
|
||||
verify: (
|
||||
req: http.IncomingMessage,
|
||||
res: http.ServerResponse,
|
||||
buf: Buffer,
|
||||
encoding: string
|
||||
) => {
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
app.use(jsonParser);
|
||||
|
||||
// send any data, it should be parsed and printed
|
||||
app.all('/', (req, res, next) => {
|
||||
console.log(req.body);
|
||||
|
||||
26
types/body-parser/index.d.ts
vendored
26
types/body-parser/index.d.ts
vendored
@@ -1,24 +1,30 @@
|
||||
// Type definitions for body-parser 1.16
|
||||
// Type definitions for body-parser 1.17
|
||||
// Project: https://github.com/expressjs/body-parser
|
||||
// Definitions by: Santi Albo <https://github.com/santialbo>, Vilic Vane <https://github.com/vilic>, Jonathan Häberle <https://github.com/dreampulse>, Gevik Babakhani <https://github.com/blendsdk>, Tomasz Łaziuk <https://github.com/tlaziuk>
|
||||
// Definitions by: Santi Albo <https://github.com/santialbo>
|
||||
// Vilic Vane <https://github.com/vilic>
|
||||
// Jonathan Häberle <https://github.com/dreampulse>
|
||||
// Gevik Babakhani <https://github.com/blendsdk>
|
||||
// Tomasz Łaziuk <https://github.com/tlaziuk>
|
||||
// Jason Walton <https://github.com/jwalton>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Request, RequestHandler, Response } from 'express';
|
||||
import { NextHandleFunction } from 'connect';
|
||||
import * as http from 'http';
|
||||
|
||||
// for docs go to https://github.com/expressjs/body-parser/tree/1.16.0#body-parser
|
||||
|
||||
// @deprecated
|
||||
declare function bodyParser(options?: bodyParser.OptionsJson & bodyParser.OptionsText & bodyParser.OptionsUrlencoded): RequestHandler;
|
||||
declare function bodyParser(options?: bodyParser.OptionsJson & bodyParser.OptionsText & bodyParser.OptionsUrlencoded): NextHandleFunction;
|
||||
|
||||
declare namespace bodyParser {
|
||||
interface Options {
|
||||
inflate?: boolean;
|
||||
limit?: number | string;
|
||||
type?: string | string[] | ((req: Request) => any);
|
||||
verify?(req: Request, res: Response, buf: Buffer, encoding: string): void;
|
||||
type?: string | string[] | ((req: http.IncomingMessage) => any);
|
||||
verify?(req: http.IncomingMessage, res: http.ServerResponse, buf: Buffer, encoding: string): void;
|
||||
}
|
||||
|
||||
interface OptionsJson extends Options {
|
||||
@@ -35,13 +41,13 @@ declare namespace bodyParser {
|
||||
parameterLimit?: number;
|
||||
}
|
||||
|
||||
function json(options?: OptionsJson): RequestHandler;
|
||||
function json(options?: OptionsJson): NextHandleFunction;
|
||||
|
||||
function raw(options?: Options): RequestHandler;
|
||||
function raw(options?: Options): NextHandleFunction;
|
||||
|
||||
function text(options?: OptionsText): RequestHandler;
|
||||
function text(options?: OptionsText): NextHandleFunction;
|
||||
|
||||
function urlencoded(options?: OptionsUrlencoded): RequestHandler;
|
||||
function urlencoded(options?: OptionsUrlencoded): NextHandleFunction;
|
||||
}
|
||||
|
||||
export = bodyParser;
|
||||
|
||||
Reference in New Issue
Block a user