0

I'm making a PATCH request from a client running on localhost:3000 with the following code:

axios.patch( "http://localhost:3090/v1/users/etc/etc/etc", { name, url, }, { headers: { authorization: AUTH_TOKEN() } } ) 

To a server configured as follows:

var app = express(); var cors = require('cors'); //etc //var whitelist = [ // 'http://localhost:3000', // 'localhost:3000' //]; //passing this to cors() doesn't help //var globalCorsOptions = { // origin: function(origin, callback) { // callback(null, whitelist.indexOf(origin) !== -1); // } //}; app.use(morgan('combined')); app.use(cors()); app.options('*', cors()); app.use(bodyParser.json({type:'*/*'})); app.use('/v1', router); var port = process.env.PORT || 3090; var ip = process.env.IP || 'localhost'; var server = http.createServer(app); server.listen(port, ip); 

But the request just hangs. I can do POST/GET fine, but not DELETE/PATCH. The preflight happens fine but the actual request following just sits "stalled" indefinitely. Here's the headers for each request:

enter image description here enter image description here

Sorry to ask this pretty standard question, but I've tried everything.

EDIT: Added the following to router (still not working):

var router = express.Router(); router.use(function(req, res, next) { res.header("Access-Control-Allow-Headers", "PATCH,DELETE,OPTIONS,GET,POST"); next(); }); 

The actual error: enter image description here

3
  • I don't think "connection refused" has anything to do with CORS. Commented Jun 12, 2016 at 13:20
  • Yeah. The problem you're seeing is not related to CORS being enabled. If CORS was the problem, the Chrome error would say so. Commented Jun 12, 2016 at 13:21
  • Yes, I agree. Do you use Fiddler? Commented Jun 12, 2016 at 13:22

1 Answer 1

1

On the server you have to add following header to the response:

headers.Add("Access-Control-Allow-Headers", "PATCH,DELETE,GET,POST");

Actually all HTTP methods you want to allow.

Sign up to request clarification or add additional context in comments.

1 Comment

Shouldn't be necessary, the cors middleware will take care of this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.