Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ProxyConfigArray in type def is not an Array #4163

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,15 @@ const schema = require("./options.json");
* @callback ByPass
* @param {Request} req
* @param {Response} res
* @param {ProxyConfigArray} proxyConfig
* @param {ProxyConfigArrayItem} proxyConfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something wrong here ByPass can't have ByPass inside

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't actually run the code yet, but looked at line 2222 it seemed to just pass the whole proxyConfig as-is:

const isByPassFuncDefined =
  typeof proxyConfig.bypass === "function";
const bypassUrl = isByPassFuncDefined
  ? await proxyConfig.bypass(req, res, proxyConfig)
  : null;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide configuration where we have a problem with types?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure~ I've put a minimial repro. in the original issue #4161, but I made a mistake during cleanup codes, fixed now:

import type { Configuration } from 'webpack-dev-server'
const apiPrefixes: string[] = ['/api/']
const devServerOptions: Configuration = {
  proxy: [
    {
      // TS2322: Type '{ context: string[]; target: string; }' is not assignable to type 'Options'.
      // Object literal may only specify known properties, and 'context' does not exist in type 'Options'.
      context: apiPrefixes,
      target : '',
    },
  ],
}

That code works when using the old @types/webpack-dev-server, but throws TS error when using webpack-dev-server's new bundle types. (And it actually works if I just ignores the TS type error)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have more errors - try #4173

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4173 works for my case, should I close this one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, let's close, merged #4173, anyway thanks for PR

*/

/**
* @typedef {{ path?: string | string[] | undefined, context?: string | string[] | HttpProxyMiddlewareOptionsFilter | undefined } & HttpProxyMiddlewareOptions & ByPass} ProxyConfigArray
* @typedef {{ path?: string | string[] | undefined, context?: string | string[] | HttpProxyMiddlewareOptionsFilter | undefined } & HttpProxyMiddlewareOptions & ByPass} ProxyConfigArrayItem
*/

/**
* @typedef {ProxyConfigArrayItem[]} ProxyConfigArray
*/

/**
Expand Down Expand Up @@ -194,7 +198,7 @@ const schema = require("./options.json");
* @property {boolean} [http2]
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
* @property {ProxyConfigMap | ProxyConfigArray | ProxyArray} [proxy]
* @property {ProxyConfigMap | ProxyConfigArray | ProxyConfigArrayItem | ProxyArray} [proxy]
* @property {boolean | string | Open | Array<string | Open>} [open]
* @property {boolean} [setupExitSignals]
* @property {boolean | ClientConfiguration} [client]
Expand Down Expand Up @@ -2130,7 +2134,7 @@ class Server {
const { createProxyMiddleware } = require("http-proxy-middleware");

/**
* @param {ProxyConfigArray} proxyConfig
* @param {ProxyConfigArrayItem} proxyConfig
* @returns {RequestHandler | undefined}
*/
const getProxyMiddleware = (proxyConfig) => {
Expand Down