首页 > 解决方案 > react-boilerplate yarn start:prod 无法访问此站点 localhost 拒绝连接。http://localhost:3000 => https://localhost/

问题描述

https://github.com/react-boilerplate/react-boilerplate

描述

运行 yarn run build 后, yarn start:prod 它说它正在终端窗口上运行,但是,当我转到http://localhost:3000 时,url 突然变为 => https://localhost/ 并说 this site无法访问 localhost 拒绝连接。

开发模式 yarn start 工作正常

重现步骤

我按照 react-boilerplate 中的问题之一的指南删除了 ImmutableJS。

我添加了feathersJS 后端、前端。

我将 webpack.base.babel.js 中的 babel-loader 更改为

rules: [
  {
    test: /\.js$/, // Transform all .js files required somewhere with Babel
    exclude: /node_modules/,
    use: {
      loader: 'babel-loader',
      options: options.babelQuery,
      query: {
        plugins: [
          ["import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" }]
       ],
     },
    },
  },

我更改了 app.js 文件

// Install ServiceWorker and AppCache in the end since
// it's not most important operation and if main code fails,
// we do not want it installed
if (process.env.NODE_ENV === 'production') {
  // require('offline-plugin/runtime').install(); // eslint-disable-line global-require
  const runtime = require('offline-plugin/runtime');

  runtime.install({
    onUpdating: () => {
      console.log('SW Event:', 'onUpdating');
    },
    onUpdateReady: () => {
      console.log('SW Event:', 'onUpdateReady');
      // Tells to new SW to take control immediately
      runtime.applyUpdate();
    },
    onUpdated: () => {
      console.log('SW Event:', 'onUpdated');
      // Reload the webpage to load into the new version
      window.location.reload();
    },

    onUpdateFailed: () => {
      console.log('SW Event:', 'onUpdateFailed');
    }
  });
}

非常感谢您的帮助!

(如果可能,在https://jsfiddle.net或类似网站上添加演示链接)

版本

标签: node.jsreactjswebpackfeathersjsreact-boilerplate

解决方案


我忘记了我正在使用 ssl-redirect 进行 heroku 部署。

var sslRedirect = require('heroku-ssl-redirect');
// heroku enable ssl redirect
app.use(sslRedirect()); //heroku https

干杯:)


推荐阅读