Javascript 从webpack localhost server使用goole api时出现访问控制允许源错误

Javascript 从webpack localhost server使用goole api时出现访问控制允许源错误,javascript,reactjs,google-api,webpack,cors,Javascript,Reactjs,Google Api,Webpack,Cors,我正在尝试执行来自的get请求,但不断收到此错误 请求的服务器上不存在“Access Control Allow Origin”标头 资源。因此,不允许使用源“” 进入 我在我的webpack-deve服务器中设置了头:{'Access-Control-Allow-Origin':'*},但仍然收到错误。任何人都知道我在这里遗漏了什么来阻止这个错误 版本:网页1.13.3 var ExtractTextPlugin = require('extract-text-webpack-plugin

我正在尝试执行来自的get请求,但不断收到此错误

请求的服务器上不存在“Access Control Allow Origin”标头 资源。因此,不允许使用源“” 进入

我在我的webpack-deve服务器中设置了头:{'Access-Control-Allow-Origin':'*},但仍然收到错误。任何人都知道我在这里遗漏了什么来阻止这个错误

版本:网页1.13.3

  var ExtractTextPlugin = require('extract-text-webpack-plugin');

    function getDevTool() {
        if (process.env.NODE_ENV !== 'production') {
            return 'source-map'; //enables source map
        }

        return false;
    }

    module.exports = {
        entry: {
            main: './src/scripts/index.js'
        },
        output: {
            filename: './build/scripts/[name].js'
        },
        devtool: getDevTool(),
        devServer: {
            port: 3000,
            hot: true,
            historyApiFallback: true,
          headers: { 'Access-Control-Allow-Origin': '*' }
        },
        module: {
            loaders: [
                {
                    test: /\.js$/,
                    exclude: 'node_modules',
                    loader: 'babel',
                    query: {
                        presets: ['react', 'es2015', 'stage-1']
                    }
                },
                {
                    test: /\.scss$/,
                    loader: ExtractTextPlugin.extract('css!sass')
                }
            ]
        },
        plugins: [
            new ExtractTextPlugin('build/styles/main.css', {
                allChunks: true
            })
        ]
    };

网页包标题仅适用于向本地服务器发出的请求(对的请求)。您提出的请求不得支持跨来源请求

请与谷歌的联系。快速查看表明,他们希望API密钥永远不会发送到客户端浏览器,因此他们不允许跨源请求


您可能需要创建自己的服务器,以代表您的用户发出这些API请求。

我已经在添加API密钥,但您没有抓住要点。API密钥的存在正好解释了为什么谷歌会阻止来自浏览器的请求。重读我的帖子。