Comparing version 0.0.1 to 0.0.2
@@ -1,3 +0,4 @@ | ||
import { Hono } from 'hono'; | ||
import { Context, Env, Hono } from 'hono'; | ||
declare const envObject: Record<string, string | undefined>; | ||
type Listener = { | ||
@@ -12,3 +13,11 @@ port: number; | ||
export declare function middlewareHandler(app: Hono, serveOptions?: Listener, pullZoneHandlerOptions?: PullZoneHandlerOptions): void; | ||
export type BunnyBindings = Partial<{ | ||
request: Request; | ||
response: Response; | ||
}> & typeof envObject; | ||
export interface BunnyEnv extends Env { | ||
Bindings: BunnyBindings; | ||
} | ||
export declare function env<E extends Env = any>(c: Context<E>): BunnyBindings & E["Bindings"]; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
var B=Object.defineProperty,v=(n,t)=>{for(var e in t)B(n,e,{get:t[e],enumerable:!0})},y={};v(y,{http:()=>E,socketAddr:()=>D,tcp:()=>P});var P={};v(P,{bind:()=>O,isTcpListener:()=>S,toString:()=>K,unstable_local_addr:()=>x,unstable_new:()=>R});var k=n=>(n=n.toLowerCase(),n.includes("ios")?"iOS":n==="android"?"Android":n==="darwin"?"MacOS":n==="win32"?"Windows":n==="freebsd"?"FreeBSD":n==="openbsd"?"OpenBSD":n==="linux"?"Linux":n?`Other:${n}`:"Unknown"),_=()=>{if(typeof Bunny<"u")return{_tag:"_Platform",version:"0.11.2",name:"Unknown",runtime:"bunny",runtime_version:"unknown"};if(typeof Deno<"u"&&Deno.build!=null)return{_tag:"_Platform",version:"0.11.2",name:k(Deno.build.os),runtime:"deno",runtime_version:typeof Deno.version=="string"?Deno.version:Deno.version?.deno??"unknown"};let n=globalThis.process;return Object.prototype.toString.call(typeof n<"u"?n:0)==="[object process]"?{_tag:"_Platform",version:"0.11.2",name:k(n.platform),runtime:"node",runtime_version:n.version}:{_tag:"_Platform",version:"0.11.2",name:"Unknown",runtime:"unknown",runtime_version:"unknown"}},D={};v(D,{InvalidAddr:()=>Z,isV4:()=>$,v4:()=>s});var s={};v(s,{ip:()=>V,port:()=>T,tryFromString:()=>U});function H(n){return`${n[0]}.${n[1]}.${n[2]}.${n[3]}`}function I(n){let t=n.split(".").map(Number);return t.length!==4||t.some(e=>isNaN(e)||e<0||e>255)?new SyntaxError("Invalid IP address"):[t[0],t[1],t[2],t[3]]}function T(n){return n.port}function V(n){return n.ip}function U(n){let t=n.split(":");if(t.length!==2)return new SyntaxError("Invalid SocketAddrV4 address");let e=I(t[0]);if(e instanceof SyntaxError)return e;let r=Number(t[1]);return isNaN(r)||r<0||r>65535?new SyntaxError("Invalid Port"):{_tag:"SocketAddrV4",port:r,ip:e}}function $(n){return n._tag==="SocketAddrV4"}var F=Symbol("invalidAddr"),Z=class extends Error{_guard=F;constructor(n){super(n),this.name="InvalidAddr"}toString(){return`${this.name}: ${this.message}`}};function S(n){return n instanceof Object&&n._tag==="TcpListener"}function x(n){return n.addr}function K(n){switch(n.addr._tag){case"SocketAddrV4":return`${s.ip(n.addr).join(".")}:${s.port(n.addr)}`;case"NoAddr":return"No addr associated to this listener. You should be running in a controlled environment."}}function R(){switch(_().runtime){case"bunny":return{_tag:"TcpListener",addr:{_tag:"NoAddr"}};default:return{_tag:"TcpListener",addr:{_tag:"SocketAddrV4",port:8080,ip:[127,0,0,1]}}}}function O(n){return{_tag:"TcpListener",addr:n}}var E={};v(E,{serve:()=>N,servePullZone:()=>W});var M={get:()=>{}},z=new Proxy({},M);function A(n){return n instanceof Response}function C(n){return n instanceof Request}function L(n){if(typeof n=="object"&&n!==null){let t=n.port;return t!==void 0&&typeof t=="number"&&n.hostname!==void 0}return!1}function N(n,t){let e,r;if(L(n)){let o=s.tryFromString(`${n.hostname}:${n.port}`);if(o instanceof Error)throw o;r=O(o),e=t}else S(n)?(e=t,r=n):(e=n,r=R());if(e===void 0)throw new Error("An issue happened.");switch(_().runtime){case"bunny":return Bunny.v1.serve(e),{};case"node":return(void 0)(r,e);case"deno":{let o=x(r);if(!$(o))throw new Error("An issue happened with the addr.");let c=s.port(o),h=H(s.ip(o));return Deno.serve({port:c,hostname:h},e),{}}case"unknown":return{}}}function W(n,t){let e,r={url:"https://bunny.net"};if(t&&(r=t),L(n)){let i=s.tryFromString(`${n.hostname}:${n.port}`);if(i instanceof Error)throw i;e=O(i)}else S(n)?e=n:(n&&(r=n),e=R());let o=[],c=[],h=_();switch(h.runtime){case"bunny":{Bunny.v1.registerMiddlewares({onOriginRequest:o,onOriginResponse:c});break}default:N(e,async i=>{let w=new URL(i.url),b=new URL(r.url);w.protocol=b.protocol,w.hostname=b.hostname,w.port=b.port;let g=new Request(w,i);for(let[f,m]of o.entries()){let u=await m({request:g});if(A(u))return u;C(u)&&(g=u)}let a=await fetch(g),d=new Headers;for(let[f,m]of a.headers.entries())d.set(f,m);let l;switch(h.runtime){case"node":{if(d.get("content-type")==="text/html"&&a.body!==null){let f=await a.text();d.delete("content-encoding"),l=new Response(f,{headers:d})}else l=new Response(a.body,{...a,headers:d});break}default:l=new Response(a.body,{...a,headers:d})}for(let[f,m]of c.entries()){let u=await m({request:g,response:l});A(u)&&(l=u)}return l})}let p={};return p.onOriginResponse=i=>(c.push(i),p),p.onOriginRequest=i=>(o.push(i),p),p}var j=Deno.env.toObject(),q={port:8080,hostname:"127.0.0.1"};function G(n,t=q){y.http.serve(t,async e=>await n.fetch(e,{...j,request:e}))}function J(n,t=q,e){async function r(o){return await n.fetch(o.request,{...j,...o})}y.http.servePullZone(t,e).onOriginResponse(r)}export{J as middlewareHandler,G as standaloneHandler}; | ||
var N=Object.defineProperty,m=(n,t)=>{for(var e in t)N(n,e,{get:t[e],enumerable:!0})},w={};m(w,{http:()=>$,socketAddr:()=>P,tcp:()=>E});var E={};m(E,{bind:()=>B,isTcpListener:()=>S,toString:()=>C,unstable_local_addr:()=>D,unstable_new:()=>R});var O=n=>(n=n.toLowerCase(),n.includes("ios")?"iOS":n==="android"?"Android":n==="darwin"?"MacOS":n==="win32"?"Windows":n==="freebsd"?"FreeBSD":n==="openbsd"?"OpenBSD":n==="linux"?"Linux":n?`Other:${n}`:"Unknown"),_=()=>{if(typeof Bunny<"u")return{_tag:"_Platform",version:"0.11.2",name:"Unknown",runtime:"bunny",runtime_version:"unknown"};if(typeof Deno<"u"&&Deno.build!=null)return{_tag:"_Platform",version:"0.11.2",name:O(Deno.build.os),runtime:"deno",runtime_version:typeof Deno.version=="string"?Deno.version:Deno.version?.deno??"unknown"};let n=globalThis.process;return Object.prototype.toString.call(typeof n<"u"?n:0)==="[object process]"?{_tag:"_Platform",version:"0.11.2",name:O(n.platform),runtime:"node",runtime_version:n.version}:{_tag:"_Platform",version:"0.11.2",name:"Unknown",runtime:"unknown",runtime_version:"unknown"}},P={};m(P,{InvalidAddr:()=>Z,isV4:()=>A,v4:()=>s});var s={};m(s,{ip:()=>V,port:()=>I,tryFromString:()=>U});function H(n){return`${n[0]}.${n[1]}.${n[2]}.${n[3]}`}function T(n){let t=n.split(".").map(Number);return t.length!==4||t.some(e=>isNaN(e)||e<0||e>255)?new SyntaxError("Invalid IP address"):[t[0],t[1],t[2],t[3]]}function I(n){return n.port}function V(n){return n.ip}function U(n){let t=n.split(":");if(t.length!==2)return new SyntaxError("Invalid SocketAddrV4 address");let e=T(t[0]);if(e instanceof SyntaxError)return e;let r=Number(t[1]);return isNaN(r)||r<0||r>65535?new SyntaxError("Invalid Port"):{_tag:"SocketAddrV4",port:r,ip:e}}function A(n){return n._tag==="SocketAddrV4"}var F=Symbol("invalidAddr"),Z=class extends Error{_guard=F;constructor(n){super(n),this.name="InvalidAddr"}toString(){return`${this.name}: ${this.message}`}};function S(n){return n instanceof Object&&n._tag==="TcpListener"}function D(n){return n.addr}function C(n){switch(n.addr._tag){case"SocketAddrV4":return`${s.ip(n.addr).join(".")}:${s.port(n.addr)}`;case"NoAddr":return"No addr associated to this listener. You should be running in a controlled environment."}}function R(){switch(_().runtime){case"bunny":return{_tag:"TcpListener",addr:{_tag:"NoAddr"}};default:return{_tag:"TcpListener",addr:{_tag:"SocketAddrV4",port:8080,ip:[127,0,0,1]}}}}function B(n){return{_tag:"TcpListener",addr:n}}var $={};m($,{serve:()=>j,servePullZone:()=>W});var K={get:()=>{}},z=new Proxy({},K);function k(n){return n instanceof Response}function M(n){return n instanceof Request}function q(n){if(typeof n=="object"&&n!==null){let t=n.port;return t!==void 0&&typeof t=="number"&&n.hostname!==void 0}return!1}function j(n,t){let e,r;if(q(n)){let o=s.tryFromString(`${n.hostname}:${n.port}`);if(o instanceof Error)throw o;r=B(o),e=t}else S(n)?(e=t,r=n):(e=n,r=R());if(e===void 0)throw new Error("An issue happened.");switch(_().runtime){case"bunny":return Bunny.v1.serve(e),{};case"node":return(void 0)(r,e);case"deno":{let o=D(r);if(!A(o))throw new Error("An issue happened with the addr.");let p=s.port(o),g=H(s.ip(o));return Deno.serve({port:p,hostname:g},e),{}}case"unknown":return{}}}function W(n,t){let e,r={url:"https://bunny.net"};if(t&&(r=t),q(n)){let i=s.tryFromString(`${n.hostname}:${n.port}`);if(i instanceof Error)throw i;e=B(i)}else S(n)?e=n:(n&&(r=n),e=R());let o=[],p=[],g=_();switch(g.runtime){case"bunny":{Bunny.v1.registerMiddlewares({onOriginRequest:o,onOriginResponse:p});break}default:j(e,async i=>{let h=new URL(i.url),b=new URL(r.url);h.protocol=b.protocol,h.hostname=b.hostname,h.port=b.port;let y=new Request(h,i);for(let[f,v]of o.entries()){let u=await v({request:y});if(k(u))return u;M(u)&&(y=u)}let a=await fetch(y),d=new Headers;for(let[f,v]of a.headers.entries())d.set(f,v);let l;switch(g.runtime){case"node":{if(d.get("content-type")==="text/html"&&a.body!==null){let f=await a.text();d.delete("content-encoding"),l=new Response(f,{headers:d})}else l=new Response(a.body,{...a,headers:d});break}default:l=new Response(a.body,{...a,headers:d})}for(let[f,v]of p.entries()){let u=await v({request:y,response:l});k(u)&&(l=u)}return l})}let c={};return c.onOriginResponse=i=>(p.push(i),c),c.onOriginRequest=i=>(o.push(i),c),c}var x=globalThis?.process?.env??Deno.env.toObject(),L={port:8080,hostname:"127.0.0.1"};function G(n,t=L){w.http.serve(t,async e=>await n.fetch(e,{...x,request:e}))}function J(n,t=L,e){async function r(o){return await n.fetch(o.request,{...x,...o})}w.http.servePullZone(t,e).onOriginResponse(r)}function X(n){return n.env??x}export{X as env,J as middlewareHandler,G as standaloneHandler}; |
{ | ||
"name": "bunny-hono", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "type": "module", |
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
41516
38