webpack / webpack-dev-server

Serves a webpack app. Updates the browser on changes. Documentation https://webpack.js.org/configuration/dev-server/.
MIT License
7.78k stars 1.43k forks source link

Host error during proxying #1944

Closed deissh closed 5 years ago

deissh commented 5 years ago

Code

/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
const webpack = require('webpack');

module.exports = {
  devtool: 'inline-source-map',
  mode: 'development',
  devServer: {
    hot: true,
    inline: true,
    proxy: {
      '/api': {
        target: 'http://somesecreturl.ru',
        secure: false,
      },
      '/kv': {
        target: 'http://somesecreturl.ru',
        secure: false,
      },
      changeOrigin: false,
    },
  },
  entry: {
    tree7: './static/js/tree7_init.js',
    login: './static/js/modules/login.js',
    signup: './static/js/modules/signup.js',
    password_recovery: './static/js/modules/password_recovery.js',
    request_map_access: './static/js/modules/request_map_access.js',
    user: './static/js/modules/user.js',
    admin: './static/js/admin_init.js',
    forgotten_password: './static/js/modules/forgotten_password.js',
  },
  output: {
    // сделать что бы был хеш filename: '[name].[contenthash].js',
    filename: 'js/[name].js',
    publicPath: 'static/dist',
    path: path.resolve(__dirname, 'static/dist'),
  },
  resolve: {
    alias: {
      TweenMax: 'gsap/src/uncompressed/TweenMax.js',
      TweenLite: 'gsap/src/uncompressed/TweenLite.js',
      // с uncompresed не собираеться
      Draggable: 'gsap/src/uncompressed/utils/Draggable.js',
      // moment: path.resolve(__dirname, 'static/vendor/agui/lib/moment/moment.js'),
      jquery: 'jquery',
    },
  },
  plugins: [
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery',
      'window.jQuery': 'jquery',
      'window.$': 'jquery',
      alight: 'alight',
      'window.alight': 'alight',
      // alight: 'static/vendor/agui/al/alight.js'
    }),
    new webpack.HashedModuleIdsPlugin(),
  ],
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components|vendor)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'],
          },
        },
      },
      {
        test: /\.css$/,
        loaders: ['style-loader', 'css-loader?sourceMap'],
      },
      {
        test: /\.(jpe?g|png|gif)$/i,
        loader: 'file-loader',
      },
      {
        test: /\.(ttf|eot|svg)(\?[\s\S]+)?$/,
        use: 'file-loader',
      },
      {
        test: /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        use: 'url-loader?limit=10000',
      },
    ],
  },
};

Expected Behavior

All requests must be proxied to an external server and processed correctly. The problem is definitely not in the API.

Actual Behavior

If you use any examples, then error 404 from NGINX is returned. Because Host is not specified correctly, namely http://localhost:8080/login.html instead of http://somesecreturl.ru/api

For Bugs; How can we reproduce the behaviour?

_-_

For Features; What is the motivation and/or use-case for the feature?

alexander-akait commented 5 years ago

Please create minimum reproducible test repo

alexander-akait commented 5 years ago

Friendly ping

deissh commented 5 years ago

resolved the problem was that in the batch code, the request was sent with the current address from window.location.pathname, and when launched via the webpack-dev-server they logged in through login.html and therefore the request was not formed correctly