minimalistic-server 0.0.49 → 0.0.51
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/index.mjs +18 -9
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -729,6 +729,7 @@ const mimeTypes = {
|
|
|
729
729
|
"zip": "application/zip",
|
|
730
730
|
"zir": "application/vnd.zul",
|
|
731
731
|
"zmm": "application/vnd.handheld-entertainment+xml",
|
|
732
|
+
__proto__: null,
|
|
732
733
|
};
|
|
733
734
|
|
|
734
735
|
export function getServerFsPromiseModule() {
|
|
@@ -740,6 +741,14 @@ export function setServerFsPromiseModule(fsPromiseModule) {
|
|
|
740
741
|
clearStaticCache();
|
|
741
742
|
}
|
|
742
743
|
|
|
744
|
+
export function getExtension(fileNameOrPath) {
|
|
745
|
+
return fileNameOrPath?.toLowerCase().split('.').at(-1) ?? '';
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
export function getContentTypeByExtension(fileNameOrPath) {
|
|
749
|
+
return mimeTypes[getExtension(fileNameOrPath)] ?? 'application/octet-stream';
|
|
750
|
+
}
|
|
751
|
+
|
|
743
752
|
export class UploadedFile {
|
|
744
753
|
#content;
|
|
745
754
|
#contentType;
|
|
@@ -760,11 +769,11 @@ export class UploadedFile {
|
|
|
760
769
|
}
|
|
761
770
|
|
|
762
771
|
getExtension() {
|
|
763
|
-
return this.#fileName
|
|
772
|
+
return getExtension(this.#fileName);
|
|
764
773
|
}
|
|
765
774
|
|
|
766
775
|
getContentTypeByExtension() {
|
|
767
|
-
return
|
|
776
|
+
return getContentTypeByExtension(this.#fileName);
|
|
768
777
|
}
|
|
769
778
|
|
|
770
779
|
getFileName() {
|
|
@@ -805,13 +814,13 @@ export class Request {
|
|
|
805
814
|
this.#method = request.method.toUpperCase();
|
|
806
815
|
|
|
807
816
|
for (const k in request.headers) {
|
|
808
|
-
this.#headers
|
|
817
|
+
Object.defineProperty(this.#headers, k.toLowerCase(), { value: request.headers[k] });
|
|
809
818
|
}
|
|
810
819
|
|
|
811
820
|
this.#path = url.pathname.split('/').filter(x => x).join('/');
|
|
812
821
|
|
|
813
822
|
url.searchParams.forEach((v, k) => {
|
|
814
|
-
this.#queryParams
|
|
823
|
+
Object.defineProperty(this.#queryParams, k, { value: v });
|
|
815
824
|
});
|
|
816
825
|
}
|
|
817
826
|
|
|
@@ -989,7 +998,7 @@ export class Request {
|
|
|
989
998
|
parent[index] = nextParent;
|
|
990
999
|
}
|
|
991
1000
|
} else if (!(parent instanceof Array) && !curFragment.match(/^-?\d+$/gm)) {
|
|
992
|
-
parent
|
|
1001
|
+
Object.defineProperty(parent, curFragment, { value: nextFragment });
|
|
993
1002
|
} else {
|
|
994
1003
|
break;
|
|
995
1004
|
}
|
|
@@ -1091,7 +1100,7 @@ export class Request {
|
|
|
1091
1100
|
}
|
|
1092
1101
|
|
|
1093
1102
|
if (name in data && !Array.isArray(data[name])) {
|
|
1094
|
-
data
|
|
1103
|
+
Object.defineProperty(data, name, { value: [data[name]] });
|
|
1095
1104
|
}
|
|
1096
1105
|
|
|
1097
1106
|
if (Array.isArray(data[name])) {
|
|
@@ -1100,7 +1109,7 @@ export class Request {
|
|
|
1100
1109
|
}
|
|
1101
1110
|
|
|
1102
1111
|
} else {
|
|
1103
|
-
data
|
|
1112
|
+
Object.defineProperty(data, name, { value });
|
|
1104
1113
|
}
|
|
1105
1114
|
}
|
|
1106
1115
|
|
|
@@ -2239,7 +2248,7 @@ function normalizeRoutes(routes, handleServerError) {
|
|
|
2239
2248
|
|
|
2240
2249
|
for (const fragment of split) {
|
|
2241
2250
|
if (!parent[fragment]) {
|
|
2242
|
-
parent[fragment] = {};
|
|
2251
|
+
parent[fragment] = { __proto__: null };
|
|
2243
2252
|
}
|
|
2244
2253
|
|
|
2245
2254
|
parent = parent[fragment];
|
|
@@ -2367,7 +2376,7 @@ async function handleRequest(req, routes, staticFileDirectories, handleNotFoundE
|
|
|
2367
2376
|
if (!newRouteHandler) {
|
|
2368
2377
|
for (let k in routeHandler) {
|
|
2369
2378
|
if (k.match(/^{\w+}$/gm)) {
|
|
2370
|
-
pathParams
|
|
2379
|
+
Object.defineProperty(pathParams, k.replace(/[{}]/gm, ''), { value: decodeURIComponent(fragment) });
|
|
2371
2380
|
newRouteHandler = routeHandler[k];
|
|
2372
2381
|
break;
|
|
2373
2382
|
}
|