-1

I have my website in main domain, like http://www.example.com and my api in https://api.example.com and I'm trying to get data from the api with vue and axios and always I get CORS error

Access to XMLHttpRequest at 'http://www.api.example.com/api/posts' from origin 'http://www.example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

. How can I solve this?

1 Answers1

0

Your backend is not accepting Cross Origin Requests. If you are using Node-Express then you will have to install then you can use the CORS npm module

$ npm install -S cors

app.js

let express = require('express')
let cors = require('cors')

let app = express()

app.use(cors())

app.listen(3000)
Miguel Coder
  • 1,896
  • 19
  • 36