My server (written with Django
) is running at http://localhost:8000
.
The Nuxt
application is running at http://localhost:3000
.
When I send a request (like http://localhost:8000/api/v1/user/position/
) to the server, I get the following error in the firefox
browser.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading
the remote resource at http://localhost:8000/api/v1/user/position/.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Firefox:
Chrome:
I saw this link and this but I do not know where the problem comes from?
Below is a section of my nuxt.config.js
file.
modules: [
'@nuxtjs/axios',
'@nuxtjs/proxy'
],
axios: {
baseURL: 'http://localhost:8000/api/v1/',
},
And function that I'm sending a request:
async getAllPosition() {
this.loading_position = true;
await this.$axios.get('user/position/').then(response => {
this.position = response.data;
}).finally(() => {
this.loading_position = false;
})
}
I think it's about proxy, but i don't know how to config it.
question from:
https://stackoverflow.com/questions/65871711/cors-missing-allow-origin 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…