如何使反应应用程序在端口8080和0.0.0.0上运行?

时间:2018-01-09 05:28:20

标签: node.js reactjs webpack webpack-dev-server package.json

我已经构建了一个 react 应用程序,它运行在 localhost:8080 ,现在我想将其更改为 0.0.0.0:80 使其公开访问,但遗憾的是我无法访问。

Webpack file:

var config = {
   entry: [
    './main.js'
 ],

   output: {
      path:'D:\\reactApps\\RouterExample',
      filename: 'index.js',
   },

   devServer: {
    inline: true,
    host: '0.0.0.0',
    port: 80,
   },

   module: {
      loaders: [
         {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',

            query: {
               presets: ['es2015', 'react']
            }
         },{
            test: /\.css$/,
             exclude: /node_modules/,
            loader: 'style-loader'
         }, {
            test: /\.css$/,
             exclude: /node_modules/,
            loader: 'css-loader',
            query: {
                modules: true,
                localIdentName: '[name]__[local]___[hash:base64:5]'
            }
         }
      ]
   }

}

module.exports = config;

package.json file:

{
  "name": "routerexample",
  "version": "1.0.0",
  "description": "new app",
  "main": "index.js",
  "dependencies": {
    "axios": "^0.16.2",
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "css-loader": "^0.28.4",
    "react": "^15.6.1",
    "react-autocomplete": "^1.7.1",
    "react-bootstrap": "^0.31.1",
    "react-bootstrap-alert": "^1.0.7",
    "react-bootstrap-dialog": "^0.9.1",
    "react-bootstrap-typeahead": "^2.0.0-alpha.3",
    "react-dom": "^15.6.1",
    "react-number-format": "^3.0.2",
    "react-router": "^4.1.2",
    "react-router-dom": "^4.1.2",
    "style-loader": "^0.18.2",
    "underscore": "^1.8.3",
    "webpack": "^3.3.0",
    "webpack-dev-server": "^2.5.1"
  },
  "scripts": {
    "start": "webpack-dev-server --hot --history-api-fallback"
  },
  "author": "",
  "license": "ISC"
}

编辑-1:

我想将我的应用程序配置为可通过url访问,例如(xyz.com)而不是localhost,它是如何实现的??

提前感谢您的建议。

1 个答案:

答案 0 :(得分:2)

尝试转到http://localhost:80

0.0.0.0不是合法地址。它只是意味着,无论机器的分配地址是什么。