@kubun/plugin-http 0.8.0 → 0.8.1
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/lib/index.js +1 -1
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defer as t}from"@enkaku/async";import{ServerTransport as e}from"@enkaku/http-server-transport";import{serve as r}from"@hono/node-server";import o from"get-port";import{Hono as n}from"hono";function i(t){return null==t?["*"]:"string"==typeof t?t.split(",").map(t=>t.trim()):t}function s(t){return async e=>t(e.req.raw)}export function createGraphApp(t){let r=new n,o=new e({allowedOrigin:i(t.allowedOrigin)}),p=s(o.fetch.bind(o)),a=t.rpc.serve(o);return r.post("/graph",p),r.post("/graph/*",p),r.options("/graph",p),r.options("/graph/*",p),{app:r,async dispose(){await a.dispose()}}}export function createHTTPPlugin(p){return a=>{let l,g,c,h,u=new n,f=t(),w=i(p?.allowedOrigin),d=p?.prefix??"/",m="/"===d?"":d.endsWith("/")?d.slice(0,-1):d,y=new Map;u.get(`${m}/health`,t=>t.json({status:"ok"})),u.get(`${m}/info`,t=>{let e={};for(let[t,r]of y)e[t]=r;return t.json({did:a.identity.id,protocols:e})});let P={listening:null,registerRoute(t,e,r){u[t.toLowerCase()](e,r)},registerProtocol(t,e){let r=`${m}/${t}`;y.set(t,r);let o=s(e);u.post(r,o),u.post(`${r}/*`,o),u.options(r,o),u.options(`${r}/*`,o)},getPort(){if(null==l)throw Error("HTTP server is not listening yet");return l},getURL(){if(null==g)throw Error("HTTP server is not listening yet");return g}},v=(async()=>{
|
|
1
|
+
import{defer as t}from"@enkaku/async";import{ServerTransport as e}from"@enkaku/http-server-transport";import{serve as r}from"@hono/node-server";import o from"get-port";import{Hono as n}from"hono";function i(t){return null==t?["*"]:"string"==typeof t?t.split(",").map(t=>t.trim()):t}function s(t){return async e=>t(e.req.raw)}export function createGraphApp(t){let r=new n,o=new e({allowedOrigin:i(t.allowedOrigin)}),p=s(o.fetch.bind(o)),a=t.rpc.serve(o);return r.post("/graph",p),r.post("/graph/*",p),r.options("/graph",p),r.options("/graph/*",p),{app:r,async dispose(){await a.dispose()}}}export function createHTTPPlugin(p){return a=>{let l,g,c,h,u=new n,f=t(),w=i(p?.allowedOrigin),d=p?.prefix??"/",m="/"===d?"":d.endsWith("/")?d.slice(0,-1):d,y=new Map;u.get(`${m}/health`,t=>t.json({status:"ok"})),u.get(`${m}/info`,t=>{let e={};for(let[t,r]of y)e[t]=r;return t.json({did:a.identity.id,protocols:e})});let P={listening:null,registerRoute(t,e,r){u[t.toLowerCase()](e,r)},registerProtocol(t,e){let r=`${m}/${t}`;y.set(t,r);let o=s(e);u.post(r,o),u.post(`${r}/*`,o),u.options(r,o),u.options(`${r}/*`,o)},getPort(){if(null==l)throw Error("HTTP server is not listening yet");return l},getURL(){if(null==g)throw Error("HTTP server is not listening yet");return g}},v=(async()=>{let t=p?.port??await o({port:4321}),n=new e({allowedOrigin:w});P.registerProtocol("graph",n.fetch.bind(n)),h=(await a.engine.getAPI("rpc")).serve(n),c=r({fetch:u.fetch,port:t},t=>{l=t.port,g=`http://localhost:${t.port}`,f.resolve()}),await f.promise})();return P.listening=v,{name:"http",api:P,async dispose(){await h?.dispose(),c?.close()}}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/plugin-http",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -18,17 +18,17 @@
|
|
|
18
18
|
"@enkaku/http-server-transport": "^0.14.2",
|
|
19
19
|
"@enkaku/protocol": "^0.14.0",
|
|
20
20
|
"@enkaku/server": "^0.14.3",
|
|
21
|
-
"@hono/node-server": "^1.19.
|
|
21
|
+
"@hono/node-server": "^1.19.14",
|
|
22
22
|
"get-port": "^7.2.0",
|
|
23
|
-
"hono": "^4.12.
|
|
24
|
-
"@kubun/engine": "^0.8.
|
|
23
|
+
"hono": "^4.12.14",
|
|
24
|
+
"@kubun/engine": "^0.8.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@enkaku/http-client-transport": "^0.14.3",
|
|
28
|
-
"@kubun/protocol": "^0.8.0",
|
|
29
|
-
"@kubun/plugin-rpc": "^0.8.0",
|
|
30
28
|
"@kubun/test-utils": "^0.8.0",
|
|
31
|
-
"@kubun/
|
|
29
|
+
"@kubun/plugin-rpc": "^0.8.1",
|
|
30
|
+
"@kubun/client": "^0.8.0",
|
|
31
|
+
"@kubun/protocol": "^0.8.0"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build:clean": "del lib",
|