Is there a way to enable CORS
access in a project built with vue-cli
and without node.js
or express.js
? I attempted to solve this by adding code to the vue.config.js
file:
vue.config.js
:
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://18.700.121.3:8000/',
ws: true,
changeOrigin: true
}
}
}
}
Vue template
import axios from 'axios';
export default {
name: "Jokes",
data () {
return {
songs: null,
}
},
mounted () {
const config = { headers: {'Access-Control-Allow-Origin': '*'}};
axios.get('http://2.788.121.2:4000/', config)
.then(response => (this.songs = response.data))
}
}
Unfortunately, these attempts did not resolve the issue. I also tried using the Chrome plugin Access-Control-Allow-Origin
, allowing access to localhost:8080
, but it still didn't work. It seems that installing node.js and adding a header such as res.header("Access-Control-Allow-Headers","*") may be the only solution.