Express / Webpack does not work for docking and geroku

PROCFILE:

build: npm run prod
web: nodemon server.js

Package.json

  "scripts": {
    "prod": "NODE_ENV=production webpack -p --config ./webpack.prod.config.js --progress --optimize-dupe"
  }

Webpack.prod.config:

var path = require('path');
var webpack = require('webpack');

module.exports = {
  devtool: null,
  entry: [
    './assets/js/index'
  ],
  output: {
    path: path.join(__dirname, 'public/dist/'),
    filename: 'bundle.js',
    publicPath: '/public/'
  },
  plugins: [
    new webpack.optimize.UglifyJsPlugin({
      minimize: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.DefinePlugin({
      'process.env': { NODE_ENV: '"production"' }
    })
  ],
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel',
        include: path.join(__dirname, 'assets/js'),
        exclude: path.join(__dirname, 'node_modules/')
      },
      {
        test: /\.css$/,
        include: path.join(__dirname, 'assets/css'),
        loader: 'style-loader!css-loader'
      }
    ]
  }
}

Server.js:

var path = require('path'),
    express = require('express'),
    app = express(),
    port = process.env.PORT || 5000

app.use(express.static(path.join(__dirname, 'public')))

app.get('*', function(req, res) {
  res.sendFile(path.join(__dirname + '/index.html'))
})

var server = app.listen(port, function() {
    var host = server.address().address
    console.log('Listening at http://%s:%s', host, port)
})

Errors:

Dokku, 502 Bad Gateway:

2016/03/03 22:43:12 [error] 5419#0: *303 connect() failed (111: Connection refused) while connecting to upstream, client: 185.49.14.190, server: xxx.xxx, request: "GET http://testp3.pospr.waw.pl/testproxy.php HTTP/1.1", upstream: "http://172.17.0.4:5000/testproxy.php", host: "testp3.pospr.waw.pl"
2016/03/03 23:54:58 [error] 5419#0: *305 connect() failed (111: Connection refused) while connecting to upstream, client: 185.49.14.190, server: xxx.xxx, request: "GET http://testp4.pospr.waw.pl/testproxy.php HTTP/1.1", upstream: "http://172.17.0.4:5000/testproxy.php", host: "testp4.pospr.waw.pl"
2016/03/04 00:55:35 [error] 5419#0: *307 connect() failed (111: Connection refused) while connecting to upstream, client: 207.46.13.22, server: xxx.xxx, request: "GET /robots.txt HTTP/1.1", upstream: "http://172.17.0.4:5000/robots.txt", host: "artempixel.com.br"
2016/03/04 00:55:41 [error] 5419#0: *309 connect() failed (111: Connection refused) while connecting to upstream, client: 207.46.13.22, server: xxx.xxx, request: "GET / HTTP/1.1", upstream: "http://172.17.0.4:5000/", host: "artempixel.com.br"

There are no errors in Heroku logs, only on the interface:

Uncaught SyntaxError: Unexpected token < - bundle.js:1

npm run prodshould create a file in /public/dist/, as it is done on my local computer, but this directory is missing from the heroku instance or dokku instance, the error does not appear that he could not create it, but if I try heroku run --app app mkdir public/dist, it will fail, as if I'm trying to get access to the directory, which he simply "created", it does not exist. I also tried to manually start npm run prod, it succeeds, dir is not created, no errors are presented.

, , - , bundle.js index.html, , , bundle.js , , , app.get('*') index.html .

, index.html bundle.js, React -, heroku, - ?

+4
2

-, , :

app.get('*', function(req, res) {
  res.sendFile(path.join(__dirname + '/index.html'))
})

bundle.js , bundle.js index.html, HTML , <, , .

, app.get('*'). , , , URL- URL-, URL- . , , , , "/" URL- ajax api.

, , , , webpack dev , . .

. , , :

app.use('/dist', express.static(path.join(__dirname, 'dist')));

'/dist', , , , webpack.

+6

:

postinstall package.json, Procfile, , , dist .

index.html, bundle.js, : /public/dist/bundle.js, : /public/public/dist/bundle.js.

dokku, , .

0

All Articles