0

So I followed one (out of many) tutorials on own to create and use your own SSL self signed certificate to enable HTTPS on both the front and backend on a Hipster monolith sample app.

relevant from .yo-rc.json:

"jhipsterVersion": "4.8.2", "websocket": "spring-websocket"

I was able to make it work and enable https both in the backend and the frontend (with different certificates).

I was also able to re-enable BrowserSync functionality with success so as not to hinder the frontend development process.

But I'm struggling with the websockets part (an endpoint on the backend that comes preconfigured in the jHipster code) which simply doesn't not get proxied neither by BrowserSync nor Node. As soon as I login with an user I receive an error message such as:

[HPM] Error occurred while trying to proxy request /websocket/tracker/info?access_token=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTUwNjUzMTEwMn0.T5t-bq3w-ow_kO0eK_DkSpS2xF17_Sc_Avz7Haof4Q6vBwy2Yo3Bx8w1q0gj1eznFrerpAHFRLWGhZ4vu2EK7A&t=1506444702511 from localhost:9060 to ws://127.0.0.1:8443 (ECONNRESET)

localhost:9060 is my BrowserSync endpoint and the ws://127.0.0.1:8443 the websockets one.

Where can I configure this? I've tried webpack.dev.js but can't seem to find the proper configs.

  • Have you tried changing ws:// to wss://? That's the secure version of websockets – Jon Ruddell Sep 26 '17 at 17:32
  • I did, exactly the same error. [HPM] Error occurred while trying to proxy request /websocket/tracker/info?access_token=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTUwNjU4OTE4Nn0.WTKAZYik_USoLeAt0lLlpVRXSsn7gSgbrxoYusGDVl3tfyuk1l2uk9o-Ix5Om_JDJ0rr_-2CCnjzF3ik3CSpUA&t=1506502786929 from localhost:9060 to wss://127.0.0.1:8443 (ECONNRESET) – João Macedo Pinto Sep 27 '17 at 09:00

1 Answers1

0

I also get this error and to avoid it, i only enable the https on webpack-dev-server (not using jhipster tls profile). Since my production environment is accessed by the client via reverse proxy with https enabled (ngix) to java server (wildfly), i don't need to enable https in the spring configuration.

If you see the webpack configuration below, the proxy target is targeting http endpoint.

FYI, I set the key and certificate on root_project/tls folder.

Here is my webpack dev server configuration:

const webpack = require('webpack');
const writeFilePlugin = require('write-file-webpack-plugin');
const webpackMerge = require('webpack-merge');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
const path = require('path');
const sass = require('sass');

const utils = require('./utils.js');
const commonConfig = require('./webpack.common.js');

const ENV = 'development';

module.exports = (options) => webpackMerge(commonConfig({env: ENV}), {
  devtool: 'eval-source-map',
  devServer: {
    contentBase: './target/classes/static/',
    proxy: [{
      context: [
        '/api',
        '/services',
        '/management',
        '/swagger-resources',
        '/v2/api-docs',
        '/h2-console',
        '/auth',
        '/captcha.jpg'
      ],
      target: `http://localhost:7777`,
      secure: false,
      changeOrigin: options.tls
    }, {
      context: [
        '/ws'
      ],
      target: `ws://localhost:7777`,
      changeOrigin: options.tls,
      secure: false,
      ws: true
    }],
    stats: options.stats,
    watchOptions: {
      ignored: /node_modules/
    },
    https: {
      key: 'tls/localhost.key',
      cert: 'tls/localhost.crt',
    },
    historyApiFallback: true
  },
  entry: {
    polyfills: './src/main/webapp/app/polyfills',
    global: './src/main/webapp/content/scss/global.scss',
    main: './src/main/webapp/app/app.main'
  },
  output: {
    path: utils.root('target/classes/static/'),
    filename: 'app/[name].bundle.js',
    chunkFilename: 'app/[id].chunk.js'
  },
  module: {
    rules: [{
      test: /\.ts$/,
      enforce: 'pre',
      loader: 'tslint-loader',
      exclude: [/(node_modules)/, new RegExp('reflect-metadata\\' + path.sep + 'Reflect\\.ts')]
    },
      {
        test: /\.ts$/,
        use: [
          'angular2-template-loader',
          {
            loader: 'cache-loader',
            options: {
              cacheDirectory: path.resolve('target/cache-loader')
            }
          },
          {
            loader: 'thread-loader',
            options: {
              // There should be 1 cpu for the fork-ts-checker-webpack-plugin.
              // The value may need to be adjusted (e.g. to 1) in some CI environments,
              // as cpus() may report more cores than what are available to the build.
              workers: require('os').cpus().length - 1
            }
          },
          {
            loader: 'ts-loader',
            options: {
              transpileOnly: true,
              happyPackMode: true
            }
          },
          'angular-router-loader'
        ],
        exclude: /(node_modules)/
      },
      {
        test: /\.scss$/,
        use: ['to-string-loader', 'css-loader', {
          loader: 'sass-loader',
          options: {implementation: sass, sourceMap: true}
        }],
        exclude: /(vendor\.scss|global\.scss)/
      },
      {
        test: /(vendor\.scss|global\.scss)/,
        use: ['style-loader', 'css-loader', 'postcss-loader', {
          loader: 'sass-loader',
          options: {implementation: sass, sourceMap: true}
        }]
      }]
  },
  stats: process.env.JHI_DISABLE_WEBPACK_LOGS ? 'none' : options.stats,
  plugins: [
    process.env.JHI_DISABLE_WEBPACK_LOGS
      ? null
      : new SimpleProgressWebpackPlugin({
        format: options.stats === 'minimal' ? 'compact' : 'expanded'
      }),
    new FriendlyErrorsWebpackPlugin(),
    new ForkTsCheckerWebpackPlugin(),
    new BrowserSyncPlugin({
      https: {
        key: 'tls/localhost.key',
        cert: 'tls/localhost.crt',
      },
      host: 'localhost',
      port: 9000,
      proxy: {
        target: `http${options.tls ? 's' : ''}://localhost:9060`,
        ws: true,
        proxyOptions: {
          changeOrigin: false  //pass the Host header to the backend unchanged  https://github.com/Browsersync/browser-sync/issues/430
        }
      },
      rewriteRules: [
        {
          match: /Content-Security-Policy/,
          fn: function (match) {
            return "DISABLED-Content-Security-Policy";
          }
        }
      ],
      socket: {
        clients: {
          heartbeatTimeout: 60000
        }
      }
    }, {
      reload: false
    }),
    new webpack.ContextReplacementPlugin(
      /angular(\\|\/)core(\\|\/)/,
      path.resolve(__dirname, './src/main/webapp/')
    ),
    new writeFilePlugin(),
    new webpack.WatchIgnorePlugin([
      utils.root('src/test'),
    ])
  ].filter(Boolean),
  mode: 'development'
});

nirleka
  • 3
  • 2