仅在具有XHR的Firefox中出错

时间:2016-10-17 22:28:21

标签: javascript node.js firefox express webpack

我部署了NodeJS + Webpack网站,并试图通过Firefox访问它。我没有通过Chrome的问题,但通过Firefox,它给我带来了以下两个错误:

GET XHR https://test-server.com:8080/__webpack_hmr

Firefox can’t establish a connection to the server at https://test-server.com:8080/__webpack_hmr

似乎无法弄清问题是什么。我可能做错了什么?

以下是我的客户端NodeJS / ExpressJS服务器的设置方式:

var express = require('express');
var path = require('path');
var config = require('../webpack.config.js');
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var app = express();
var compiler = webpack(config);

app.use(webpackDevMiddleware(compiler, {noInfo: true, publicPath: config.output.publicPath}));

app.use(webpackHotMiddleware(compiler));

app.use(express.static('./dist'));

function setupCORS(req, res, next) {    
  res.header('Access-Control-Allow-Origin', '*')
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Allow-Credentials, X-Access-Token, X-Key")
  res.header("Access-Control-Allow-Credentials", "true")

  if (req.method === 'OPTIONS') {
      res.status(200).end();
  } else {
      next();
  }
}
app.all('/*', setupCORS);

app.get('/', function (req, res) {
    res.sendFile(path.resolve('client/index.html'))
});

var port = 3000;

app.listen(port, function(error) {
    if (error) throw error;
    console.log("Express server listening on port", port);
});

我的index.html

<!doctype html>
<html class="no-js" lang="">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="description" content="Testing application">

    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, user-scalable=0, maximum-scale=1, minimum-scale=1"
    >
    <link rel="stylesheet" type="text/css" href="app.css">
  </head>

  <body>
    <div id="app"></div>
    <script>
      var WebFontConfig = {
        google: { families: [ 'Roboto:400,300,500:latin' ] }
      };
      (function() {
        var wf = document.createElement('script');
        wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
        '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
        wf.type = 'text/javascript';
        wf.async = 'true';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(wf, s);
      })();
    </script>
    <script src="bundle.js"></script>
  </body>
</html>

以及我如何提出API请求:

  fetch(`https://kcs-dev.karmaautomotive.com:8443/user`, config)
  .then(userInfo => userInfo.json())

接受并提出答案。 提前谢谢

0 个答案:

没有答案