Skip to content
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

POST request timeout and BadRequestError: request aborted #286

Open
bitk0der opened this issue Oct 17, 2020 · 2 comments
Open

POST request timeout and BadRequestError: request aborted #286

bitk0der opened this issue Oct 17, 2020 · 2 comments

Comments

@bitk0der
Copy link

bitk0der commented Oct 17, 2020

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);
});
@Rob--W
Copy link
Owner

Rob--W commented Oct 17, 2020

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?

@tszsau
Copy link

tszsau commented Dec 7, 2020

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" }

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

No branches or pull requests

3 participants