@jsenv/server
Advanced tools
Comparing version 12.6.0 to 12.6.1
{ | ||
"name": "@jsenv/server", | ||
"version": "12.6.0", | ||
"version": "12.6.1", | ||
"description": "Write your Node.js server using pure functions", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -42,3 +42,3 @@ /* | ||
canReadDirectory = false, | ||
rootDirectoryUrl, | ||
rootDirectoryUrl, // = `${pathToFileURL(process.cwd())}/`, | ||
} = {}, | ||
@@ -48,3 +48,3 @@ ) => { | ||
if (!urlString) { | ||
return send500DueToFilesystemUrlParameter( | ||
return create500Response( | ||
`fetchFileSystem first parameter must be a file url, got ${filesystemUrl}`, | ||
@@ -54,6 +54,23 @@ ) | ||
if (!urlString.startsWith("file://")) { | ||
return send500DueToFilesystemUrlParameter( | ||
return create500Response( | ||
`fetchFileSystem url must use "file://" scheme, got ${filesystemUrl}`, | ||
) | ||
} | ||
if (rootDirectoryUrl) { | ||
let rootDirectoryUrlString = asUrlString(rootDirectoryUrl) | ||
if (!rootDirectoryUrlString) { | ||
return create500Response( | ||
`rootDirectoryUrl must be a string or an url, got ${rootDirectoryUrl}`, | ||
) | ||
} | ||
if (!rootDirectoryUrlString.endsWith("/")) { | ||
rootDirectoryUrlString = `${rootDirectoryUrlString}/` | ||
} | ||
if (!urlString.startsWith(rootDirectoryUrlString)) { | ||
return create500Response( | ||
`fetchFileSystem url must be inside root directory, got ${urlString}`, | ||
) | ||
} | ||
rootDirectoryUrl = rootDirectoryUrlString | ||
} | ||
@@ -186,3 +203,3 @@ // here you might be tempted to add || cacheControl === 'no-cache' | ||
const send500DueToFilesystemUrlParameter = (message) => { | ||
const create500Response = (message) => { | ||
return { | ||
@@ -426,3 +443,2 @@ status: 500, | ||
} | ||
if (typeof value === "string") { | ||
@@ -432,3 +448,2 @@ if (isFileSystemPath(value)) { | ||
} | ||
try { | ||
@@ -441,4 +456,3 @@ const urlObject = new URL(value) | ||
} | ||
return null | ||
} |
@@ -31,3 +31,2 @@ // https://github.com/node-fetch/node-fetch/blob/8c197f8982a238b3c345c64b17bfa92e16b4f7c4/src/response.js#L1 | ||
if (url.startsWith("file://")) { | ||
const origin = new URL(url).origin | ||
const responseProperties = await fetchFileSystem(url, { | ||
@@ -37,3 +36,3 @@ signal, | ||
headers, | ||
rootDirectoryUrl: origin, | ||
rootDirectoryUrl: "file://", | ||
cacheStrategy, | ||
@@ -40,0 +39,0 @@ canReadDirectory, |
import { readdirSync } from "node:fs" | ||
import { pathToFileURL } from "node:url" | ||
@@ -8,3 +7,3 @@ import { negotiateContentType } from "./content_negotiation/negotiateContentType.js" | ||
url, | ||
{ headers = {}, rootDirectoryUrl = `${pathToFileURL(process.cwd())}/` } = {}, | ||
{ headers = {}, rootDirectoryUrl } = {}, | ||
) => { | ||
@@ -11,0 +10,0 @@ url = String(url) |
135565
4248