Sockjs-node Heroku ERR_CONNECTION_REFUSED

时间:2017-07-29 13:20:22

标签: node.js heroku webpack

我是webpackNodeJS的新手。我有一个工作正常的本地Web应用程序。当我将它部署到Heroku时,我收到此错误:

  

GET http:// {example.com}:28203 / sockjs-node / info?t = 1501331942755 net :: ERR_CONNECTION_REFUSED

以下是Heroku的webpack.config.js

const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
  entry: './app/javascripts/app.js',
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'app.js'
  },
  plugins: [
    // Copy our app's index.html to the build folder.
    new CopyWebpackPlugin([
      { from: './app/index.html', to: "index.html" }
    ])
  ],
  module: {
    rules: [
      {
       test: /\.css$/,
       use: [ 'style-loader', 'css-loader' ]
      }
    ],
    loaders: [
      { test: /\.json$/, use: 'json-loader' },
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['es2015'],
          plugins: ['transform-runtime']
        }
      }
    ]
  },
  devServer: {
    port: process.env.PORT || 8080,
    host: '0.0.0.0',
    disableHostCheck: true
  },
}

有什么建议吗?感谢

编辑:我正在添加条目文件app.js删除不必要的部分,并基本关注应用程序准备就绪时应执行的内容:

// Import libraries
import { default as Web3} from 'web3';
import { templates } from '../javascripts/templates.js';
import { default as contract } from 'truffle-contract'

//...

$( document ).ready(function() {
  if (typeof web3 !== 'undefined') {
    console.warn("Using web3 detected from external source like Metamask")
    // Use Mist/MetaMask's provider
    window.web3 = new Web3(web3.currentProvider);
  } else {
    // fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
    window.web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
  }

  account = web3.eth.accounts[parseInt(prompt("Select an Ethereum address..."))];//web3.eth.accounts[1];
  ForwardPayment.setProvider(web3.currentProvider);
  MatchPay.setProvider(web3.currentProvider);


  let filter = web3.eth.filter({fromBlock: 0, address: master_address, topics: [web3.sha3("Created(address,address,address)"), topicize(account), null, null]});
  filter.get(function(error, result) {
     reconstruct(result);
  });

  let in_filter = web3.eth.filter({fromBlock: 0, address: master_address, topics: [web3.sha3("Created(address,address,address)"), null, topicize(account), null]});
  in_filter.get(function(error, result) {
     in_reconstruct(result);
  });

  // look for newly created contracts
  let new_in_filter = web3.eth.filter({address: master_address, topics: [web3.sha3("Created(address,address,address)"), null, topicize(account), null]});
  new_in_filter.watch(function(error, receipt) {
    let contr_address = "0x" + receipt['topics'][3].substring(26);
    in_handler(contr_address, "0x" + receipt.topics[1].substring(26));
  });

});

1 个答案:

答案 0 :(得分:1)

我使用自己的域名和https进行开发。那些我的配置。 a screenshoot,有效

//nginx config
server {
    listen 80;
    listen 443 ssl;
    #server_name  ;
    #ssl_certificate      
    #ssl_certificate_key  

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:3000;
    }

    location /sockjs-node/ {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /api {
        proxy_pass   http://127.0.0.1:8080;
    }
}

//my webpack version
"webpack-dev-server": "2.11.2",
"webpack": "3.12.0"

//webpack.config.dev.js
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const buildConfig = require('./package.json');

const buildName = buildConfig.name;
const buildVersion = buildConfig.version;

module.exports = {
    devtool: 'eval',
    entry: {
        app: [
            'react-hot-loader/patch',
            'webpack-dev-server/client?https://0.0.0.0',
            'webpack/hot/only-dev-server', // Reload only the dev server
            'index.js'
        ]

    },
    output: {
        path: path.resolve(__dirname, '/static'),
        publicPath: '/static',
        hashDigestLength: 5,
        filename: `myapp-${buildVersion}-[name].min.js`
    },
    module: {
        rules: [{
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel-loader'
        },
        {
            test: /\.css$/,
            loader: 'style-loader!css-loader'
        },
        {
            test: /\.(jpg|png|svg)$/,
            loader: 'url-loader?limit=500000'
        },
        {
            test: /\.(ttf|eot|woff|woff2|svg)$/,
            loader: 'url-loader?limit=50000'
        },
        {
            test: /\.scss$/,
            loader: 'style!css!sass'
        },
        {
            test: /\.wasm$/,
            loaders: ['wasm-loader']
        }
        ]
    },
    resolve: {
        extensions: ['.js', '.jsx']
    },
    context: __dirname,
    target: 'web',
    devServer: {
        //        contentBase: './static',
        //       compress: true,
        host: '0.0.0.0',
        port: 3000,
        disableHostCheck: true,
        hot: true, // Activate hot loading
        headers: {
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
        },
        watchOptions: {
            aggregateTimeout: 300,
            poll: 1000
        }
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify('development')
        })
    ],
};


//server.js
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const webpackConfig = require('./webpack.config.dev');

function runFunc(err) {
    if (err) {
        console.log(err);
    }
    console.log('Listening at localhost:3000');
}

new WebpackDevServer(webpack(webpackConfig), {
    publicPath: '/static',
    hot: true,
    host: '0.0.0.0',
    disableHostCheck: true,
    historyApiFallback: true,
    proxy: [{
        path: '/api',
        target: 'http://127.0.0.1:8080/'
    }]
}).listen(3000, '0.0.0.0', runFunc);