POST request timeout and BadRequestError: request aborted
Hello, thank you for that module.
I'm using cors-anywhere as ExpressJS middleware for GET and POST requests. GET requests working as expected, but POST request can not be parsed by target test server and body parser always gives: BadRequestError: request aborted.
Comments in example code.
Cors anywhere middleware:
var app = require('express')();
var corsAnywhere = require('cors-anywhere');
var port = 3330;
let proxy_cors = corsAnywhere.createServer({
originWhitelist: [], // for test purpose
requireHeaders: [], // for test purpose
removeHeaders: [], // for test purpose
httpProxyOptions: {
secure: false
},
});
app.get('/proxy/:proxyUrl*', async (req, res) => {
req.url = req.url.replace('/proxy/', '/');
proxy_cors.emit('request', req, res);
}); // WORKING
app.post('/proxy/:proxyUrl*', async (req, res) => {
req.url = req.url.replace('/proxy/', '/');
proxy_cors.emit('request', req, res);
}); // NOT WORKING, BECAUSE SOMETHING SENT WRONG
app.listen(port, function () {
console.log('Server started on port:', port);
});
Test ExpressJS server:
var app = require('express')();
var bodyParser = require('body-parser');
var port = 3333;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.get('/test', function (req, res) {
// WORKING FINE
res.json({status: 'ok'});
});
app.post('/test', function (req, res) {
// DIRECT CALL (without cors-anywhere) - WORKS
// CORS-ANYWHERE: REQUEST NEVER GET HERE AND AFTER TIMEOUT, BODYPARSER GOT: BadRequestError: request aborted
res.json({status: 'ok'});
});
app.listen(port, function () {
console.log('Server started on port:', port);
});
Works for me with Node v14.13.1, cors-anywhere 0.4.3, express 4.17.1, and curl http://127.0.0.1:3330/proxy/http://127.0.0.1:3333/test -dparam=value
How can this issue be reproduced?
Hi, i encounter the same issue.
i tried to do a POST request with a JSON body, i returned timeout. i've no problem when doing a GET request or a POST request without body.
here's my example of POST request:
POST http://localhost:3100/proxy/https://postman-echo.com/post
JSON body: { "test": "anything" }