Skip to content

Commit

Permalink
fix CORS preflight request. Fixes #269
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Sep 1, 2021
1 parent 9d723d8 commit 4722f78
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- add `pathToRegexpOptions` to route options to make available to pass options to `path-to-regexp` library. [#268](https://github.com/moleculerjs/moleculer-web/issues/268)
- add `debounceTime` to route options to make available to change the debounce time at service changes. [#260](https://github.com/moleculerjs/moleculer-web/issues/260)
- new `errorHandler` method to allow developers to change the default error handling behaviour. [#266](https://github.com/moleculerjs/moleculer-web/issues/266)
- fixes CORS preflight request handling in case of full-path aliases. [#269](https://github.com/moleculerjs/moleculer-web/issues/269)
- update dependencies

-----------------------------
Expand Down
3 changes: 1 addition & 2 deletions examples/cors/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"use strict";

/**
*
* Call the endpoints from https://cors-tester.glitch.me/
*/

const { ServiceBroker } = require("moleculer");
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,13 @@ module.exports = {
if (!this.routes || this.routes.length == 0)
return null;

let method = req.method;
if (method == "OPTIONS") {
method = req.headers["access-control-request-method"];
}

// Check aliases
const found = this.resolveAlias(url, req.method);
const found = this.resolveAlias(url, method);
if (found) {
const route = found.alias.route;
// Update URLs for middlewares
Expand Down

0 comments on commit 4722f78

Please sign in to comment.