@prostory/mountain
Version:
Yet another HTTP/2 server and client.
3 lines (2 loc) • 857 B
JavaScript
import{createSecureServer as e,constants as t}from"http2";import{responseFor as o}from"./plugins/response.js";import{accessRequest as a}from"./plugins/access.js";const s=(e,t,o,a)=>({flags:o,stream:e,headers:t,parameters:a}),n=(e,l)=>({on:(t,o)=>n(e,l.on(t,o)),use:(...t)=>n(e.concat(t.map((({path:e,method:t,handle:o})=>({path:new RegExp(e),method:t,handle:o})))),l),listen:(h=3333,p="localhost",r)=>n(e,l.on("stream",((n,l,h)=>{var p,r;const{url:m,method:d}=a(s(n,l,h,[])),i=e.find((({method:e,path:t})=>e===d&&t.test(m.pathname)));void 0!==i?i.handle(s(n,l,h,null!==(r=null===(p=i.path.exec(m.pathname))||void 0===p?void 0:p.slice(1))&&void 0!==r?r:[])):o(s(n,l,h,[])).header(t.HTTP2_HEADER_STATUS,String(t.HTTP_STATUS_NOT_FOUND)).end()})).listen(h,p,r)),close:t=>n(e,l.close(t))}),l=t=>n([],e(t));export{l as server};
//# sourceMappingURL=server.js.map