Skip to content

devServer proxy /api/* is actually /api #2454

@olivercoad

Description

@olivercoad
  • Operating System:
  • Node Version:
  • NPM Version:
  • webpack Version:
  • webpack-dev-server Version: 3.10.3
  • Browser:
  • This is a bug
  • This is a modification request

Code

When using the 'context': 'target' or 'context': { ...options... } style of proxy, if /* is at the end of the context it is removed.

// For backwards compatibility reasons.
const correctedContext = context
.replace(/^\*$/, '**')
.replace(/\/\*$/, '');

See discussion in #359 for why this was done

So, for a config such as this:

// webpack.config.js
module.exports = {
  //...
  devServer: {
    proxy: {
      '/api/*' : 'http://localhost:3000'
    }
  }
};

Expected Behavior

Proxies everything starting with /api/
i.e. /api/stuff but NOT /apistuff.html

Actual Behavior

Proxies everything starting with /api
including /apistuff.html

For Bugs; How can we reproduce the behavior?

  1. Create new project using The SAFE Template: dotnet new SAFE
  2. To make it clear when requests are being proxied to the server, replace use_static publicPath with use_router (text "from server") in src/Server/Server.fs
  3. Run the project using fake build -t run
  4. Observe that localhost:8080/apistuff.html results in from server, because it is being proxied to the server (whereas localhost:8080/notapistuff.html results in Cannot GET /notapistuff.html because it is not being proxied)

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

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions