Skip to content

Conversation

capaj
Copy link

@capaj capaj commented Mar 7, 2023

props to @Tokscull

@alanhe421
Copy link

so any update

// @ts-expect-error
if (req.body) {
// @ts-expect-error
let bodyData = req.rawBody
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsafe access to req.rawBody

@@ -228,6 +228,42 @@ http.createServer(function (req, res) {

**[Back to top](#table-of-contents)**

#### Forward POST requests with a json body

```ts
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { IncomingMessage, ServerResponse } from 'http'; import * as httpProxy from 'http-proxy';

add this to the first

#### Forward POST requests with a json body

```ts
const proxy = httpProxy.createProxyServer({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the const proxy = httpProxy.createProxyServer create an interface interface ExtendedIncomingMessage extends IncomingMessage { body?: any; rawBody?: Buffer | string; }

the reason to create this interface is to typeScript will catch errors if you try to access properties that don't exist. and to make it runtime error free

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants