@bool-ts/core 1.7.14 → 1.7.16
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.
- package/dist/hooks/factory.d.ts +1 -1
- package/dist/hooks/factory.js +9 -1
- package/package.json +1 -1
- package/src/hooks/factory.ts +13 -5
package/dist/hooks/factory.d.ts
CHANGED
|
@@ -66,5 +66,5 @@ export declare const moduleResolution: (module: new (...args: any[]) => unknown,
|
|
|
66
66
|
}>[];
|
|
67
67
|
routerGroup: RouterGroup;
|
|
68
68
|
}> | undefined>;
|
|
69
|
-
export declare const BoolFactory: (modules:
|
|
69
|
+
export declare const BoolFactory: (modules: Object | Array<Object>, options: TBoolFactoryOptions) => Promise<void>;
|
|
70
70
|
export default BoolFactory;
|
package/dist/hooks/factory.js
CHANGED
|
@@ -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: "
|
|
623
|
+
statusText: "Expectation Failed.",
|
|
616
624
|
headers: responseHeaders
|
|
617
625
|
}));
|
|
618
626
|
}
|
package/package.json
CHANGED
package/src/hooks/factory.ts
CHANGED
|
@@ -924,10 +924,7 @@ const fetcher = async (
|
|
|
924
924
|
);
|
|
925
925
|
};
|
|
926
926
|
|
|
927
|
-
export const BoolFactory = async (
|
|
928
|
-
modules: new (...args: any[]) => unknown | Array<new (...args: any[]) => unknown>,
|
|
929
|
-
options: TBoolFactoryOptions
|
|
930
|
-
) => {
|
|
927
|
+
export const BoolFactory = async (modules: Object | Array<Object>, options: TBoolFactoryOptions) => {
|
|
931
928
|
try {
|
|
932
929
|
const modulesConverted = !Array.isArray(modules) ? [modules] : modules;
|
|
933
930
|
const { allowLogsMethods, staticOption, allowOrigins, allowMethods, allowCredentials, allowHeaders } = Object.freeze({
|
|
@@ -968,6 +965,7 @@ export const BoolFactory = async (
|
|
|
968
965
|
const url = new URL(request.url);
|
|
969
966
|
const query = Qs.parse(url.searchParams.toString(), options.queryParser);
|
|
970
967
|
const origin = request.headers.get("origin") || "*";
|
|
968
|
+
const method = request.method.toUpperCase();
|
|
971
969
|
const responseHeaders = new Headers();
|
|
972
970
|
|
|
973
971
|
try {
|
|
@@ -980,6 +978,16 @@ export const BoolFactory = async (
|
|
|
980
978
|
allowOrigins.includes("*") ? "*" : !allowOrigins.includes(origin) ? allowOrigins[0] : origin
|
|
981
979
|
);
|
|
982
980
|
|
|
981
|
+
if (!allowMethods.includes(method)) {
|
|
982
|
+
return responseConverter(
|
|
983
|
+
new Response(undefined, {
|
|
984
|
+
status: 405,
|
|
985
|
+
statusText: "Method Not Allowed.",
|
|
986
|
+
headers: responseHeaders
|
|
987
|
+
})
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
|
|
983
991
|
if (request.method.toUpperCase() === "OPTIONS") {
|
|
984
992
|
return responseConverter(
|
|
985
993
|
allowOrigins.includes("*") || allowOrigins.includes(origin)
|
|
@@ -990,7 +998,7 @@ export const BoolFactory = async (
|
|
|
990
998
|
})
|
|
991
999
|
: new Response(undefined, {
|
|
992
1000
|
status: 417,
|
|
993
|
-
statusText: "
|
|
1001
|
+
statusText: "Expectation Failed.",
|
|
994
1002
|
headers: responseHeaders
|
|
995
1003
|
})
|
|
996
1004
|
);
|