webpack-dev-server На запрашиваемом ресурсе отсутствует заголовок «Access-Control-Allow-Origin». - PullRequest
0 голосов
/ 13 мая 2018

Я пытаюсь создать небольшое веб-приложение, используя Webpack, но я получаю эти ошибки, когда пытаюсь запустить вывод, используя webpack-dev-server

2account:1 GET https://api.digitalocean.com/v2/account 401 ()
localhost/:1 Failed to load https://api.digitalocean.com/v2/account: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 401. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
localhost/:1 Uncaught (in promise) TypeError: Failed to fetch
Promise.then (async)
(anonymous) @ index.js:4
./src/index.js @ bundle.js:3705
__webpack_require__ @ bundle.js:20
(anonymous) @ bundle.js:69
(anonymous) @ bundle.js:72

Я должен получить вывод, похожий на этот:

{
  "account": {
    "droplet_limit": 5,
    "email": "do-wrapper@do-wrapper.com",
    "uuid": "57e96b88ed1511e490ec1681e6b88ec1",
    "email_verified": true
  }
}

Вот мой webpack.config.js

  // webpack.config.js
var path = require('path');

module.exports = {
  mode: 'development',
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },

  node: {
    console: false,
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  },

  devServer: {
    headers: {
      'Access-Control-Allow-Origin': '*'
    }
  },

};

Чтобы воспроизвести ошибку клона этого репозитория Gitub и запустить npm install в каталоге, затем запустите node_modules.bin \ webpack-dev-server.cmd

...