-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a showcase how to proxy POST with a body #1629
base: master
Are you sure you want to change the base?
Conversation
so any update |
// @ts-expect-error | ||
if (req.body) { | ||
// @ts-expect-error | ||
let bodyData = req.rawBody |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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
props to @Tokscull