D
D
devilsD2018-08-01 12:51:44
CORS
devilsD, 2018-08-01 12:51:44

Why does nuxt axios have an OPTIONS method for all requests?

I connect nuxt axios to the nuxt config:
modules: [ '@nuxtjs/axios']
I do not change other parameters. When sending such a request in the component method:
this.$axios.$get(' some-host.com ') - in the console, the request has the OPTIONS method. In any get or post request, for some reason OPTIONS is substituted. If you specify the relative path this.$axios.$post('/some-url') , then the parameter with baseUrl localhost:3000 is substituted and sent by the desired method:
POST http://localhost:3000/some-url
But if you change the baseURL value to the desired host through the plugin, then again the request is made using the OPTIONS method
I managed to find out that this is related to CORS , and this problem can be solved through nuxt proxy , but I did not find a good example.

But if I directly use axios, then everything works correctly:

import axios from 'axios'
axios.get('http://some-url')

So the problem is in the nuxt axios config.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Anton, 2018-08-01
@devilsD

CORS , there is an image on the page. This makes the browser completely independent, neither nuxt nor axios has anything to do with it.

But if I directly use axios, then everything works correctly:
import axios from 'axios'
axios.get('http://some-url')

This add. the request goes only for post requests, get works without it.

I
Igor, 2019-05-11
@IgorPI

Anton Anton , you are wrong, if you execute a get request, the browser also sends OPTIONS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question