const path = require('path');

const _ = require('lodash');
const webpack = require('webpack');
const merge = require('webpack-merge');
const nodeObjectHash = require('node-object-hash');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');

const TARGET_PORT = _.get(process.env, 'npm_package_config_django_port', 8043);
const TARGET_HOST = _.get(process.env, 'npm_package_config_django_host', 'https://localhost');
const TARGET = `https://${TARGET_HOST}:${TARGET_PORT}`;
const OUTPUT = 'js/[name].js';

const development = require('./webpack.development');

const watch = {
    cache: true,
    devtool: 'cheap-source-map',
    output: {
        filename: OUTPUT
    },
    /*
     *module: {
     *    rules: [
     *        {
     *            test: /\.js$/,
     *            enforce: 'pre',
     *            exclude: /node_modules/,
     *            loader: 'eslint-loader'
     *        }
     *    ]
     *},
     */
    plugins: [
        new HtmlWebpackHarddiskPlugin(),
        new HardSourceWebpackPlugin({
            cacheDirectory: 'node_modules/.cache/hard-source/[confighash]',
            recordsPath: 'node_modules/.cache/hard-source/[confighash]/records.json',
            configHash: config => nodeObjectHash({ sort: false }).hash(config),
            environmentHash: {
                root: process.cwd(),
                directories: ['node_modules'],
                files: ['package.json']
            }
        }),
        new webpack.HotModuleReplacementPlugin()
    ],
    devServer: {
        hot: true,
        inline: true,
        contentBase: path.resolve(__dirname, '..', 'static'),
        stats: 'minimal',
        publicPath: '/static/',
        host: '127.0.0.1',
        https: true,
        port: 3000,
        https: true,
        clientLogLevel: 'none',
        proxy: {
            '/': {
                target: TARGET,
                secure: false,
                ws: false,
                bypass: req => req.originalUrl.includes('hot-update.json')
            },
            '/websocket': {
                target: TARGET,
                secure: false,
                ws: true
            },
            '/network_ui': {
                target: TARGET,
                secure: false,
                ws: true
            }
        }
    }
};

module.exports = merge(development, watch);

@@ -1832,37 +1832,16 @@
 : 3000,%0A
-        https: true,%0A
         
@@ -1879,16 +1879,17 @@
  proxy: 
+%5B
 %7B%0A      
@@ -1898,19 +1898,92 @@
     
-'/': %7B%0A    
+context: (pathname, req) =%3E !(pathname === '/api/login/' && req.method === 'POST'),%0A
     
@@ -2010,36 +2010,32 @@
 ET,%0A            
-  
-  
 secure: false,%0A 
@@ -2041,28 +2041,24 @@
             
-    
 ws: false,%0A 
@@ -2048,36 +2048,32 @@
      ws: false,%0A
-    
             bypa
@@ -2127,38 +2127,44 @@
 .json')%0A        
+%7D,%0A
     
-%7D,
+    %7B
 %0A            '/w
@@ -2164,28 +2164,32 @@
     
-'/websocket': %7B%0A    
+context: '/api/login/',%0A
     
@@ -2216,36 +2216,32 @@
 ET,%0A            
-    
 secure: false,%0A 
@@ -2255,69 +2255,232 @@
     
-    ws: true%0A            %7D,%0A            '/network_ui': %7B%0A    
+ws: false,%0A            headers: %7B%0A                Host: %60localhost:$%7BTARGET_PORT%7D%60,%0A                Origin: TARGET,%0A                Referer: %60$%7BTARGET%7D/%60%0A            %7D%0A        %7D,%0A        %7B%0A            context: '/websocket',%0A
     
@@ -2495,36 +2495,32 @@
 target: TARGET,%0A
-    
             secu
@@ -2546,34 +2546,149 @@
     
-    ws: true%0A            %7D
+ws: true%0A        %7D,%0A        %7B%0A            context: '/network_ui',%0A            target: TARGET,%0A            secure: false,%0A            ws: true
 %0A   
@@ -2689,24 +2689,25 @@
 ue%0A        %7D
+%5D
 %0A    %7D%0A%7D;%0A%0Am

Fix webpack-dev-server proxy to accommodate auth changes