@bool-ts/core 1.7.14 → 1.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -597,12 +597,20 @@ export const BoolFactory = async (modules, options) => {
597
597
  const url = new URL(request.url);
598
598
  const query = Qs.parse(url.searchParams.toString(), options.queryParser);
599
599
  const origin = request.headers.get("origin") || "*";
600
+ const method = request.method.toUpperCase();
600
601
  const responseHeaders = new Headers();
601
602
  try {
602
603
  allowCredentials && responseHeaders.set("Access-Control-Allow-Credentials", "true");
603
604
  responseHeaders.set("Access-Control-Allow-Methods", allowMethods.join(", "));
604
605
  responseHeaders.set("Access-Control-Allow-Headers", allowHeaders.join(", "));
605
606
  responseHeaders.set("Access-Control-Allow-Origin", allowOrigins.includes("*") ? "*" : !allowOrigins.includes(origin) ? allowOrigins[0] : origin);
607
+ if (!allowMethods.includes(method)) {
608
+ return responseConverter(new Response(undefined, {
609
+ status: 405,
610
+ statusText: "Method Not Allowed.",
611
+ headers: responseHeaders
612
+ }));
613
+ }
606
614
  if (request.method.toUpperCase() === "OPTIONS") {
607
615
  return responseConverter(allowOrigins.includes("*") || allowOrigins.includes(origin)
608
616
  ? new Response(undefined, {
@@ -612,7 +620,7 @@ export const BoolFactory = async (modules, options) => {
612
620
  })
613
621
  : new Response(undefined, {
614
622
  status: 417,
615
- statusText: "Origin Disallowed.",
623
+ statusText: "Expectation Failed.",
616
624
  headers: responseHeaders
617
625
  }));
618
626
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bool-ts/core",
3
- "version": "1.7.14",
3
+ "version": "1.7.15",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -968,6 +968,7 @@ export const BoolFactory = async (
968
968
  const url = new URL(request.url);
969
969
  const query = Qs.parse(url.searchParams.toString(), options.queryParser);
970
970
  const origin = request.headers.get("origin") || "*";
971
+ const method = request.method.toUpperCase();
971
972
  const responseHeaders = new Headers();
972
973
 
973
974
  try {
@@ -980,6 +981,16 @@ export const BoolFactory = async (
980
981
  allowOrigins.includes("*") ? "*" : !allowOrigins.includes(origin) ? allowOrigins[0] : origin
981
982
  );
982
983
 
984
+ if (!allowMethods.includes(method)) {
985
+ return responseConverter(
986
+ new Response(undefined, {
987
+ status: 405,
988
+ statusText: "Method Not Allowed.",
989
+ headers: responseHeaders
990
+ })
991
+ );
992
+ }
993
+
983
994
  if (request.method.toUpperCase() === "OPTIONS") {
984
995
  return responseConverter(
985
996
  allowOrigins.includes("*") || allowOrigins.includes(origin)
@@ -990,7 +1001,7 @@ export const BoolFactory = async (
990
1001
  })
991
1002
  : new Response(undefined, {
992
1003
  status: 417,
993
- statusText: "Origin Disallowed.",
1004
+ statusText: "Expectation Failed.",
994
1005
  headers: responseHeaders
995
1006
  })
996
1007
  );