@hono/vite-dev-server
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -46,37 +46,51 @@ import { getRequestListener } from "@hono/node-server"; | ||
} | ||
getRequestListener(async (request) => { | ||
let env = {}; | ||
if (options?.env) { | ||
if (typeof options.env === "function") { | ||
env = await options.env(); | ||
} else { | ||
env = options.env; | ||
getRequestListener( | ||
async (request) => { | ||
let env = {}; | ||
if (options?.env) { | ||
if (typeof options.env === "function") { | ||
env = await options.env(); | ||
} else { | ||
env = options.env; | ||
} | ||
} else if (options?.cf) { | ||
env = await cloudflarePagesGetEnv(options.cf)(); | ||
} | ||
} else if (options?.cf) { | ||
env = await cloudflarePagesGetEnv(options.cf)(); | ||
} | ||
if (options?.plugins) { | ||
for (const plugin2 of options.plugins) { | ||
if (plugin2.env) { | ||
env = typeof plugin2.env === "function" ? await plugin2.env() : plugin2.env; | ||
if (options?.plugins) { | ||
for (const plugin2 of options.plugins) { | ||
if (plugin2.env) { | ||
env = typeof plugin2.env === "function" ? await plugin2.env() : plugin2.env; | ||
} | ||
} | ||
} | ||
} | ||
let response = await app.fetch(request, env, { | ||
waitUntil: async (fn) => fn, | ||
passThroughOnException: () => { | ||
throw new Error("`passThroughOnException` is not supported"); | ||
const response = await app.fetch(request, env, { | ||
waitUntil: async (fn) => fn, | ||
passThroughOnException: () => { | ||
throw new Error("`passThroughOnException` is not supported"); | ||
} | ||
}); | ||
if (!(response instanceof Response)) { | ||
throw response; | ||
} | ||
}); | ||
if (!(response instanceof Response)) { | ||
const message = `The response is not an instance of "Response", but: ${response.toString()}`; | ||
console.error(message); | ||
response = createErrorResponse(message); | ||
if (options?.injectClientScript !== false && response.headers.get("content-type")?.match(/^text\/html/)) { | ||
const script = '<script>import("/@vite/client")</script>'; | ||
return injectStringToResponse(response, script); | ||
} | ||
return response; | ||
}, | ||
{ | ||
errorHandler: (e) => { | ||
let err; | ||
if (e instanceof Error) { | ||
err = e; | ||
server2.ssrFixStacktrace(err); | ||
} else if (typeof e === "string") { | ||
err = new Error(`The response is not an instance of "Response", but: ${e}`); | ||
} else { | ||
err = new Error(`Unknown error: ${e}`); | ||
} | ||
next(err); | ||
} | ||
} | ||
if (options?.injectClientScript !== false && response.headers.get("content-type")?.match(/^text\/html/)) { | ||
const script = '<script>import("/@vite/client")</script>'; | ||
return injectStringToResponse(response, script); | ||
} | ||
return response; | ||
})(req, res); | ||
)(req, res); | ||
}; | ||
@@ -98,21 +112,8 @@ } | ||
} | ||
function escapeHtml(str) { | ||
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"); | ||
} | ||
function createErrorResponse(body) { | ||
return new Response( | ||
`<html><body><pre style="white-space:pre-wrap;">${escapeHtml(body)}</pre></body></html>`, | ||
{ | ||
status: 500, | ||
headers: { | ||
"content-type": "text/html;charset=utf-8" | ||
} | ||
} | ||
); | ||
} | ||
function injectStringToResponse(response, content) { | ||
const stream = response.body; | ||
const newContent = new TextEncoder().encode(content); | ||
if (!stream) | ||
if (!stream) { | ||
return null; | ||
} | ||
const reader = stream.getReader(); | ||
@@ -119,0 +120,0 @@ const newContentReader = new ReadableStream({ |
{ | ||
"name": "@hono/vite-dev-server", | ||
"description": "Vite dev-server plugin for Hono", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"types": "dist/index.d.ts", | ||
@@ -76,3 +76,3 @@ "module": "dist/index.js", | ||
"dependencies": { | ||
"@hono/node-server": "^1.4.1", | ||
"@hono/node-server": "^1.7.0", | ||
"miniflare": "^3.20231218.2", | ||
@@ -79,0 +79,0 @@ "minimatch": "^9.0.3" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32532
657
Updated@hono/node-server@^1.7.0