azurajs 2.7.0 → 2.7.1
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/config.cjs.map +1 -1
- package/dist/config.d.cts +1 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js.map +1 -1
- package/dist/cors.cjs +27 -8
- package/dist/cors.cjs.map +1 -1
- package/dist/cors.d.cts +3 -2
- package/dist/cors.d.ts +3 -2
- package/dist/cors.js +27 -8
- package/dist/cors.js.map +1 -1
- package/dist/index.cjs +38 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -11
- package/dist/index.js.map +1 -1
- package/dist/infra.cjs +38 -11
- package/dist/infra.cjs.map +1 -1
- package/dist/infra.js +38 -11
- package/dist/infra.js.map +1 -1
- package/dist/plugins.cjs +27 -8
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.js +27 -8
- package/dist/plugins.js.map +1 -1
- package/package.json +1 -1
- package/src/infra/Server.ts +14 -4
- package/src/shared/config/ConfigModule.ts +2 -1
- package/src/shared/plugins/CORSPlugin.ts +33 -8
- package/src/types/plugins/cors.type.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -608,12 +608,28 @@ var COMMON_PROXY_RANGES = {
|
|
|
608
608
|
|
|
609
609
|
// src/shared/plugins/CORSPlugin.ts
|
|
610
610
|
function cors(opts) {
|
|
611
|
-
const
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
611
|
+
const allowedOrigin = opts.origin ?? "*";
|
|
612
|
+
const methods = opts.methods ?? "GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS";
|
|
613
|
+
const allowedHeaders = opts.allowedHeaders ?? "Content-Type,Authorization,Cookie,X-Requested-With,Accept";
|
|
614
|
+
const credentials = opts.credentials === true;
|
|
615
|
+
return async (ctx, next) => {
|
|
616
|
+
const requestOrigin = ctx.request.headers["origin"];
|
|
617
|
+
if (allowedOrigin === "*") {
|
|
618
|
+
if (credentials && requestOrigin) {
|
|
619
|
+
ctx.response.setHeader("Access-Control-Allow-Origin", requestOrigin);
|
|
620
|
+
} else {
|
|
621
|
+
ctx.response.setHeader("Access-Control-Allow-Origin", "*");
|
|
622
|
+
}
|
|
623
|
+
} else if (Array.isArray(allowedOrigin)) {
|
|
624
|
+
if (requestOrigin && allowedOrigin.includes(requestOrigin)) {
|
|
625
|
+
ctx.response.setHeader("Access-Control-Allow-Origin", requestOrigin);
|
|
626
|
+
}
|
|
627
|
+
} else if (allowedOrigin) {
|
|
628
|
+
ctx.response.setHeader("Access-Control-Allow-Origin", allowedOrigin);
|
|
629
|
+
}
|
|
630
|
+
if (credentials) {
|
|
631
|
+
ctx.response.setHeader("Access-Control-Allow-Credentials", "true");
|
|
632
|
+
}
|
|
617
633
|
ctx.response.setHeader(
|
|
618
634
|
"Access-Control-Allow-Methods",
|
|
619
635
|
Array.isArray(methods) ? methods.join(",") : methods
|
|
@@ -622,9 +638,12 @@ function cors(opts) {
|
|
|
622
638
|
"Access-Control-Allow-Headers",
|
|
623
639
|
Array.isArray(allowedHeaders) ? allowedHeaders.join(",") : allowedHeaders
|
|
624
640
|
);
|
|
641
|
+
ctx.response.setHeader("Vary", "Origin");
|
|
625
642
|
if (ctx.request.method === "OPTIONS") {
|
|
626
|
-
ctx.response.
|
|
627
|
-
|
|
643
|
+
ctx.response.statusCode = 204;
|
|
644
|
+
ctx.response.setHeader("Content-Length", "0");
|
|
645
|
+
ctx.response.end();
|
|
646
|
+
return;
|
|
628
647
|
}
|
|
629
648
|
return next();
|
|
630
649
|
};
|
|
@@ -936,15 +955,23 @@ var AzuraClient = class {
|
|
|
936
955
|
return;
|
|
937
956
|
}
|
|
938
957
|
if (this.opts.plugins?.cors?.enabled) {
|
|
939
|
-
cors({
|
|
958
|
+
const corsPlugin = cors({
|
|
940
959
|
origin: this.opts.plugins.cors.origins,
|
|
941
960
|
methods: this.opts.plugins.cors.methods,
|
|
942
|
-
allowedHeaders: this.opts.plugins.cors.allowedHeaders
|
|
961
|
+
allowedHeaders: this.opts.plugins.cors.allowedHeaders,
|
|
962
|
+
credentials: this.opts.plugins.cors.credentials
|
|
943
963
|
});
|
|
964
|
+
this.middlewares.unshift((ctx) => corsPlugin(ctx, ctx.next));
|
|
944
965
|
logger("info", "CORS plugin enabled");
|
|
945
966
|
}
|
|
946
967
|
if (this.opts.plugins?.rateLimit?.enabled) {
|
|
947
|
-
rateLimit(
|
|
968
|
+
const rateLimitPlugin = rateLimit(
|
|
969
|
+
this.opts.plugins.rateLimit.limit,
|
|
970
|
+
this.opts.plugins.rateLimit.timeframe
|
|
971
|
+
);
|
|
972
|
+
if (typeof rateLimitPlugin === "function") {
|
|
973
|
+
this.middlewares.unshift((ctx) => rateLimitPlugin(ctx, ctx.next));
|
|
974
|
+
}
|
|
948
975
|
logger("info", "Rate Limit plugin enabled");
|
|
949
976
|
}
|
|
950
977
|
this.server = http.createServer();
|