@wooksjs/http-static 0.4.36 → 0.5.0
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/index.cjs +1 -5
- package/dist/index.mjs +2 -6
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1202,7 +1202,6 @@ async function serveFile(filePath, options = {}) {
|
|
|
1202
1202
|
if (!options.allowDotDot && (filePath.includes('/../') || filePath.startsWith('../'))) {
|
|
1203
1203
|
throw new Error('Parent Traversal ("/../") is not allowed.');
|
|
1204
1204
|
}
|
|
1205
|
-
const { restoreCtx } = eventHttp.useHttpContext();
|
|
1206
1205
|
const { status } = eventHttp.useResponse();
|
|
1207
1206
|
const { setHeader, removeHeader } = eventHttp.useSetHeaders();
|
|
1208
1207
|
const headers = eventHttp.useHeaders();
|
|
@@ -1217,7 +1216,6 @@ async function serveFile(filePath, options = {}) {
|
|
|
1217
1216
|
if (options.defaultExt) {
|
|
1218
1217
|
const ext = path.extname(filePath);
|
|
1219
1218
|
if (!ext) {
|
|
1220
|
-
restoreCtx();
|
|
1221
1219
|
return serveFile(`${filePath}.${options.defaultExt}`);
|
|
1222
1220
|
}
|
|
1223
1221
|
}
|
|
@@ -1243,14 +1241,12 @@ async function serveFile(filePath, options = {}) {
|
|
|
1243
1241
|
}
|
|
1244
1242
|
if (fileStats.isDirectory()) {
|
|
1245
1243
|
if (options.listDirectory) {
|
|
1246
|
-
restoreCtx();
|
|
1247
1244
|
return listDirectory(normalizedPath);
|
|
1248
1245
|
}
|
|
1249
1246
|
else if (options.index) {
|
|
1250
1247
|
if (!filePath.endsWith('/') && url && !url.endsWith('/')) {
|
|
1251
1248
|
return new eventHttp.BaseHttpResponse().setStatus(302).setHeader('location', `${url}/`);
|
|
1252
1249
|
}
|
|
1253
|
-
restoreCtx();
|
|
1254
1250
|
return serveFile(path.join(filePath, options.index), {
|
|
1255
1251
|
...options,
|
|
1256
1252
|
index: '',
|
|
@@ -1273,7 +1269,7 @@ async function serveFile(filePath, options = {}) {
|
|
|
1273
1269
|
start = Number.parseInt(s);
|
|
1274
1270
|
end = e ? Number.parseInt(e) : size - 1;
|
|
1275
1271
|
end = Math.min(size - 1, end);
|
|
1276
|
-
if (start > end || isNaN(start) || isNaN(end)) {
|
|
1272
|
+
if (start > end || Number.isNaN(start) || Number.isNaN(end)) {
|
|
1277
1273
|
throw new eventHttp.HttpError(416);
|
|
1278
1274
|
}
|
|
1279
1275
|
size = end - start + 1;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useResponse, useSetHeaders, useHeaders, useRequest, useSetCacheControl, HttpError, BaseHttpResponse } from '@wooksjs/event-http';
|
|
2
2
|
import { createReadStream, promises } from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
|
|
@@ -1200,7 +1200,6 @@ async function serveFile(filePath, options = {}) {
|
|
|
1200
1200
|
if (!options.allowDotDot && (filePath.includes('/../') || filePath.startsWith('../'))) {
|
|
1201
1201
|
throw new Error('Parent Traversal ("/../") is not allowed.');
|
|
1202
1202
|
}
|
|
1203
|
-
const { restoreCtx } = useHttpContext();
|
|
1204
1203
|
const { status } = useResponse();
|
|
1205
1204
|
const { setHeader, removeHeader } = useSetHeaders();
|
|
1206
1205
|
const headers = useHeaders();
|
|
@@ -1215,7 +1214,6 @@ async function serveFile(filePath, options = {}) {
|
|
|
1215
1214
|
if (options.defaultExt) {
|
|
1216
1215
|
const ext = path.extname(filePath);
|
|
1217
1216
|
if (!ext) {
|
|
1218
|
-
restoreCtx();
|
|
1219
1217
|
return serveFile(`${filePath}.${options.defaultExt}`);
|
|
1220
1218
|
}
|
|
1221
1219
|
}
|
|
@@ -1241,14 +1239,12 @@ async function serveFile(filePath, options = {}) {
|
|
|
1241
1239
|
}
|
|
1242
1240
|
if (fileStats.isDirectory()) {
|
|
1243
1241
|
if (options.listDirectory) {
|
|
1244
|
-
restoreCtx();
|
|
1245
1242
|
return listDirectory(normalizedPath);
|
|
1246
1243
|
}
|
|
1247
1244
|
else if (options.index) {
|
|
1248
1245
|
if (!filePath.endsWith('/') && url && !url.endsWith('/')) {
|
|
1249
1246
|
return new BaseHttpResponse().setStatus(302).setHeader('location', `${url}/`);
|
|
1250
1247
|
}
|
|
1251
|
-
restoreCtx();
|
|
1252
1248
|
return serveFile(path.join(filePath, options.index), {
|
|
1253
1249
|
...options,
|
|
1254
1250
|
index: '',
|
|
@@ -1271,7 +1267,7 @@ async function serveFile(filePath, options = {}) {
|
|
|
1271
1267
|
start = Number.parseInt(s);
|
|
1272
1268
|
end = e ? Number.parseInt(e) : size - 1;
|
|
1273
1269
|
end = Math.min(size - 1, end);
|
|
1274
|
-
if (start > end || isNaN(start) || isNaN(end)) {
|
|
1270
|
+
if (start > end || Number.isNaN(start) || Number.isNaN(end)) {
|
|
1275
1271
|
throw new HttpError(416);
|
|
1276
1272
|
}
|
|
1277
1273
|
size = end - start + 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/http-static",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "@wooksjs/http-static",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"url": "https://github.com/wooksjs/wooksjs/issues"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@wooksjs/event-http": "0.
|
|
42
|
+
"@wooksjs/event-http": "0.5.0"
|
|
43
43
|
},
|
|
44
44
|
"homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/http-static#readme"
|
|
45
45
|
}
|