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
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:
varapp=require('express')();varcorsAnywhere=require('cors-anywhere');varport=3330;letproxy_cors=corsAnywhere.createServer({originWhitelist: [],// for test purposerequireHeaders: [],// for test purposeremoveHeaders: [],// for test purposehttpProxyOptions: {secure: false},});app.get('/proxy/:proxyUrl*',async(req,res)=>{req.url=req.url.replace('/proxy/','/');proxy_cors.emit('request',req,res);});// WORKINGapp.post('/proxy/:proxyUrl*',async(req,res)=>{req.url=req.url.replace('/proxy/','/');proxy_cors.emit('request',req,res);});// NOT WORKING, BECAUSE SOMETHING SENT WRONGapp.listen(port,function(){console.log('Server started on port:',port);});
Test ExpressJS server:
varapp=require('express')();varbodyParser=require('body-parser');varport=3333;app.use(bodyParser.json());app.use(bodyParser.urlencoded({extended: false}));app.get('/test',function(req,res){// WORKING FINEres.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 abortedres.json({status: 'ok'});});app.listen(port,function(){console.log('Server started on port:',port);});
The text was updated successfully, but these errors were encountered:
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:
Test ExpressJS server:
The text was updated successfully, but these errors were encountered: