@wooksjs/http-static 0.3.3 → 0.3.4

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 CHANGED
@@ -1220,6 +1220,10 @@ function getMimeType(path, fallback = null) {
1220
1220
  return extensions[ext] || fallback;
1221
1221
  }
1222
1222
 
1223
+ function normalizePath(filePath, baseDir) {
1224
+ return path.normalize(path.join(filePath.startsWith('/') || (baseDir && baseDir.startsWith('/')) ? '' : process.cwd(), baseDir || '', filePath));
1225
+ }
1226
+
1223
1227
  const { stat, readdir } = fs.promises;
1224
1228
  // export function statFile(path: string) {
1225
1229
  // return stat(path)
@@ -1232,7 +1236,7 @@ function serveFile(filePath, options = {}) {
1232
1236
  const headers = eventHttp.useHeaders();
1233
1237
  const { method, url } = eventHttp.useRequest();
1234
1238
  const { setCacheControl, setExpires, setPragmaNoCache } = eventHttp.useSetCacheControl();
1235
- const normalizedPath = path.normalize(path.join(process.cwd(), options.baseDir || '', filePath));
1239
+ const normalizedPath = normalizePath(filePath, options.baseDir);
1236
1240
  let fileStats;
1237
1241
  try {
1238
1242
  fileStats = yield stat(normalizedPath);
package/dist/index.mjs CHANGED
@@ -1218,6 +1218,10 @@ function getMimeType(path, fallback = null) {
1218
1218
  return extensions[ext] || fallback;
1219
1219
  }
1220
1220
 
1221
+ function normalizePath(filePath, baseDir) {
1222
+ return path.normalize(path.join(filePath.startsWith('/') || (baseDir && baseDir.startsWith('/')) ? '' : process.cwd(), baseDir || '', filePath));
1223
+ }
1224
+
1221
1225
  const { stat, readdir } = promises;
1222
1226
  // export function statFile(path: string) {
1223
1227
  // return stat(path)
@@ -1230,7 +1234,7 @@ function serveFile(filePath, options = {}) {
1230
1234
  const headers = useHeaders();
1231
1235
  const { method, url } = useRequest();
1232
1236
  const { setCacheControl, setExpires, setPragmaNoCache } = useSetCacheControl();
1233
- const normalizedPath = path.normalize(path.join(process.cwd(), options.baseDir || '', filePath));
1237
+ const normalizedPath = normalizePath(filePath, options.baseDir);
1234
1238
  let fileStats;
1235
1239
  try {
1236
1240
  fileStats = yield stat(normalizedPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/http-static",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "@wooksjs/http-static",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -31,7 +31,7 @@
31
31
  "url": "https://github.com/wooksjs/wooksjs/issues"
32
32
  },
33
33
  "peerDependencies": {
34
- "@wooksjs/event-http": "0.3.3"
34
+ "@wooksjs/event-http": "0.3.4"
35
35
  },
36
36
  "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/http-static#readme"
37
37
  }