You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`error`: The error event is emitted if the request to the target fail.
152
+
*`proxyRes`: This event is emitted if the request to the target got a response.
153
+
154
+
```js
155
+
var httpProxy =require('http-proxy');
156
+
// Error example
157
+
//
158
+
// Http Proxy Server with bad target
159
+
//
160
+
var proxy =httpProxy.createServer({
161
+
target:'http://localhost:9005'
162
+
});
163
+
164
+
//
165
+
// Tell the proxy to listen on port 8000
166
+
//
167
+
proxy.listen(8005);
168
+
169
+
//
170
+
// Listen for the `error` event on `proxy`.
171
+
proxy.on('error', function (err, req, res) {
172
+
res.writeHead(500, {
173
+
'Content-Type':'text/plain'
174
+
});
175
+
176
+
res.end('Something went wrong. And we are reporting a custom error message.');
177
+
});
178
+
179
+
//
180
+
// Listen for the `proxyRes` event on `proxy`.
181
+
//
182
+
proxy.on('proxyRes', function (res) {
183
+
console.log('RAW Response from the target', res.headers);
184
+
});
185
+
186
+
```
187
+
188
+
#### Using HTTPS
189
+
You can activate the validation of a secure SSL certificate to the target connection (avoid self signed certs), just set `secure: true` in the options.
190
+
191
+
##### HTTPS -> HTTP
192
+
193
+
```js
194
+
//
195
+
// Create the HTTPS proxy server in front of a HTTP server
0 commit comments