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

REST OPTIONS method request is blocked by webpack-dev-server logic #23859

Closed
1 task done
sek1973 opened this issue Sep 5, 2022 · 2 comments
Closed
1 task done

REST OPTIONS method request is blocked by webpack-dev-server logic #23859

sek1973 opened this issue Sep 5, 2022 · 2 comments

Comments

@sek1973
Copy link

sek1973 commented Sep 5, 2022

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Each OPTIONS request is automatically replaced with the 204 code type response, regardless the content and how the application intends to handle it.
OPTIONS type request is compliant with specification:
https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
and should be handled respectively.

This refers to https://github.com/webpack/webpack-dev-server/issues/4551 and partially to #23857

Minimal Reproduction

Any application using proxy functionality and sending OPTIONS requests.
Please find a basic project to reproduce this issue here: https://github.com/sek1973/options-issue.

Exception or Error

Depending on the application implementation it may cause unexpected http response for OPTIONS requests.

Your Environment

Angular CLI: 14.2.1
Node: 16.17.0
Package Manager: npm 8.18.0
OS: win32 x64

Angular: 14.2.0
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1402.1
@angular-devkit/build-angular   14.2.1
@angular-devkit/core            14.2.1
@angular-devkit/schematics      14.2.1
@angular/cli                    14.2.1
@schematics/angular             14.2.1
rxjs                            7.5.6
typescript                      4.7.4

Anything else relevant?

@angular-devkit/build-angular@14.2.1 uses webpack-dev-server@4.10.0 internally.
Commenting out or removing following code in (node_modules\webpack-dev-server\lib\Server.js) seems to fix this issue:

{
/**
 *
 * @param {Request} req
 * @param {Response} res
 * @param {NextFunction} next
 * @returns {void}
 *
 */
const optionsRequestResponseMiddleware = (req, res, next) => {
  if (req.method === "OPTIONS") {
    res.statusCode = 204;
    res.setHeader("Content-Length", "0");
    res.end();
    return;
  }
  next();
};

middlewares.push({
  name: "options-middleware",
  path: "*",
  middleware: optionsRequestResponseMiddleware,
});
}
@alan-agius4
Copy link
Collaborator

Duplicate of #23857

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants