Comparing version 0.0.2 to 0.0.3
@@ -1,2 +0,3 @@ | ||
import { Context, Env, Hono } from 'hono'; | ||
import { Context, Env, Hono, Schema } from 'hono'; | ||
import { BlankEnv, BlankSchema } from 'hono/types'; | ||
@@ -11,4 +12,4 @@ declare const envObject: Record<string, string | undefined>; | ||
}; | ||
export declare function standaloneHandler(app: Hono, serveOptions?: Listener): void; | ||
export declare function middlewareHandler(app: Hono, serveOptions?: Listener, pullZoneHandlerOptions?: PullZoneHandlerOptions): void; | ||
export declare function standaloneHandler<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = "/">(app: Hono<E, S, BasePath>, serveOptions?: Listener): void; | ||
export declare function middlewareHandler<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = "/">(app: Hono<E, S, BasePath>, serveOptions?: Listener, pullZoneHandlerOptions?: PullZoneHandlerOptions): void; | ||
export type BunnyBindings = Partial<{ | ||
@@ -15,0 +16,0 @@ request: Request; |
@@ -1,1 +0,1 @@ | ||
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}; | ||
var N=Object.defineProperty,v=(n,t)=>{for(var e in t)N(n,e,{get:t[e],enumerable:!0})},w={};v(w,{http:()=>$,socketAddr:()=>P,tcp:()=>O});var O={};v(O,{bind:()=>E,isTcpListener:()=>B,toString:()=>C,unstable_local_addr:()=>D,unstable_new:()=>x});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"),S=()=>{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"}},P={};v(P,{InvalidAddr:()=>Z,isV4:()=>A,v4:()=>i});var i={};v(i,{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 B(n){return n instanceof Object&&n._tag==="TcpListener"}function D(n){return n.addr}function C(n){switch(n.addr._tag){case"SocketAddrV4":return`${i.ip(n.addr).join(".")}:${i.port(n.addr)}`;case"NoAddr":return"No addr associated to this listener. You should be running in a controlled environment."}}function x(){switch(S().runtime){case"bunny":return{_tag:"TcpListener",addr:{_tag:"NoAddr"}};default:return{_tag:"TcpListener",addr:{_tag:"SocketAddrV4",port:8080,ip:[127,0,0,1]}}}}function E(n){return{_tag:"TcpListener",addr:n}}var $={};v($,{serve:()=>j,servePullZone:()=>W});var K={get:()=>{}},z=new Proxy({},K);function R(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=i.tryFromString(`${n.hostname}:${n.port}`);if(o instanceof Error)throw o;r=E(o),e=t}else B(n)?(e=t,r=n):(e=n,r=x());if(e===void 0)throw new Error("An issue happened.");switch(S().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 c=i.port(o),h=H(i.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),q(n)){let s=i.tryFromString(`${n.hostname}:${n.port}`);if(s instanceof Error)throw s;e=E(s)}else B(n)?e=n:(n&&(r=n),e=x());let o=[],c=[],h=S();switch(h.runtime){case"bunny":{Bunny.v1.registerMiddlewares({onOriginRequest:o,onOriginResponse:c});break}default:j(e,async s=>{let g=new URL(s.url),b=new URL(r.url);g.protocol=b.protocol,g.hostname=b.hostname,g.port=b.port;let y=new Request(g,s);for(let[f,m]of o.entries()){let u=await m({request:y});if(R(u))return u;M(u)&&(y=u)}let a=await fetch(y),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:y,response:l});R(u)&&(l=u)}return l})}let p={};return p.onOriginResponse=s=>(c.push(s),p),p.onOriginRequest=s=>(o.push(s),p),p}var _=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,{..._,request:e}))}function J(n,t=L,e){async function r(o){return await n.fetch(o.request,{..._,...o})}w.http.servePullZone(t,e).onOriginResponse(r)}function X(n){return n.env??_}export{X as env,J as middlewareHandler,G as standaloneHandler}; |
{ | ||
"name": "bunny-hono", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"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
41786
39