webpack / webpack-dev-server

Serves a webpack app. Updates the browser on changes. Documentation https://webpack.js.org/configuration/dev-server/.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proxy configuration incorrect path / target URL match

szape89 opened this issue · comments

Bug report

I have the following problem as an Angular developer with proxying: angular/angular-cli#25380
It seems that the / character is not taken into consideration in the proxy configuration file.
A request to /somethingelse/whatever matches /something/*, which does not feel right, it acts like it should for /something* (without the / character at the end).
I was directed to the http-proxy-middleware project, but I was unable to reproduce the same issue.
On the other hand I can reproduce the same using webpack-dev-server, so here I am.
This feels like a bug, but if there is a reasonable explanation, please elaborate.

Actual Behavior

A request to /somethingelse/whatever matches /something/*. Changing the order in the proxy configuration resolves the issue.

Expected Behavior

A request to /somethingelse/whatever should not match /something/*. The order in the proxy configuration should not matter.

How Do We Reproduce?

Working http-proxy-middleware code below.

const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');

const app = express();

app.use(
  '/something/*',
  createProxyMiddleware({
    target: 'http://localhost:1234'
  })
);

app.use(
  '/somethingelse/*',
  createProxyMiddleware({
    target: 'http://localhost:5678'
  })
);

app.listen(3000);

Problematic webpack proxy configs (https://webpack.js.org/configuration/dev-server/#devserverproxy) and logs below.

devServer: {
    proxy: {
      '/something/*': {
        target: 'http://localhost:1234',
      },
      '/somethingelse/*': {
        target: 'http://localhost:5678',
      },
    },
},
<i> [webpack-dev-server] [HPM] Proxy created: /something  -> http://localhost:1234
<i> [webpack-dev-server] [HPM] Proxy created: /somethingelse  -> http://localhost:5678
<e> [webpack-dev-server] [HPM] Error occurred while proxying request localhost:8080/something/ to http://localhost:1234/ [ECONNREFUSED]
<e> [webpack-dev-server] [HPM] Error occurred while proxying request localhost:8080/somethingelse/ to http://localhost:1234/ [ECONNREFUSED]
devServer: {
    proxy: {
      '/somethingelse/*': {
        target: 'http://localhost:5678',
      },
      '/something/*': {
        target: 'http://localhost:1234',
      },
    },
},
<i> [webpack-dev-server] [HPM] Proxy created: /somethingelse  -> http://localhost:5678
<i> [webpack-dev-server] [HPM] Proxy created: /something  -> http://localhost:1234
<e> [webpack-dev-server] [HPM] Error occurred while proxying request localhost:8080/somethingelse/ to http://localhost:5678/ [ECONNREFUSED]
<e> [webpack-dev-server] [HPM] Error occurred while proxying request localhost:8080/something/ to http://localhost:1234/ [ECONNREFUSED]

Please paste the results of npx webpack-cli info here, and mention other relevant information

No other relevant information.

Fixed in the master, release will be soon, sorry for delay