insite-http 2.2.0 → 2.2.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/dist/index.js +2 -2
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var m=class{listeners};var
|
|
2
|
-
`,t)}}#f=(e,t)=>{let r=decodeURI(e.url).replace(this.#t,"").replaceAll("../","");if(r=this.#n.get(r)??l.join(this.#e,r),this.#s.has(r))return!1;if(!O.existsSync(r))return t.notFound();let{mimeType:n,isText:s}=this.#
|
|
1
|
+
var m=class{listeners};var Se=void 0;import O from"node:fs";import l from"node:path";import u from"node:zlib";var se={params:{[u.constants.BROTLI_PARAM_MODE]:u.constants.BROTLI_MODE_TEXT,[u.constants.BROTLI_PARAM_QUALITY]:11}},$={params:{[u.constants.BROTLI_PARAM_MODE]:u.constants.BROTLI_MODE_TEXT,[u.constants.BROTLI_PARAM_QUALITY]:4}},ie={level:9},A={level:3};function I(o){return u.brotliCompressSync(o,se)}function C(o){return u.gzipSync(o,ie)}function k(o){return o==="br"?u.createBrotliCompress($):u.createGzip(A)}function _(o,e,t,r){let n=/\bbr\b/.test(o.headers["accept-encoding"]);t["Content-Encoding"]=n?"br":"gzip",e.writeHead(200,t).end(n?u.brotliCompressSync(r,$):u.gzipSync(r,A))}var D=[["js",{isText:!0,mimeType:"text/javascript"}],["css",{isText:!0,mimeType:"text/css"}],["ico",{mimeType:"image/x-icon"}],process.env.NODE_ENV==="development"?["css.map",{isText:!0,mimeType:"application/json"}]:null,process.env.NODE_ENV==="development"?["js.map",{isText:!0,mimeType:"application/json"}]:null,["jpg",{mimeType:"image/jpeg"}],["jpeg",{mimeType:"image/jpeg"}]].filter(Boolean);var N=[...process.env.NODE_ENV==="production"?["/index.js","/favicon.ico"]:[]];var ae={mimeType:"application/octet-stream"},E=class extends m{constructor({src:e="public",urlPrefix:t="",path:r,extensions:n=D,resolved:s,restricted:p,preloaded:a="default"}={}){if(super(),!l.isAbsolute(e)){let[,i]=process.argv;e=l.resolve(O.statSync(i).isDirectory()?i:l.dirname(i),e)}if(this.#e=e,this.#o=t,this.#t=new RegExp(`^${l.join("/",t,"/")}`),n)for(let i of n)i&&this.#p(...i);if(s)for(let i of s)i&&this.#u(...i);if(p)for(let i of p)i&&this.#l(i);if(a){a==="default"&&(a=N);for(let i of a)i&&this.#c(i)}this.listeners={GET:[[r??new RegExp(`^${l.join("/",this.#o,"/")}(\\w[^\\/]*/)*[^\\/]+\\.[^\\/]`),this.#f]]}}#e;#o;#t;#r=new Map;#n=new Map;#s=new Set;#i=new Map;#a(e){return this.#r.get(e.slice(Math.max(0,e.lastIndexOf(".")+1)))??ae}#p(e,t){this.#r.set(e,{...t,name:e})}#u(e,t){this.#n.set(e,l.isAbsolute(t)?t:l.join(this.#e,t))}#l(e){this.#s.add(l.join(this.#e,e))}#c(e){e=this.#n.get(e)??l.join(this.#e,e);try{let{isText:t}=this.#a(e),r=O.readFileSync(e,t?"utf8":null);this.#i.set(e,t?{br:I(r),gzip:C(r)}:r)}catch(t){console.warn(`\u26A0\uFE0F inSite Static Server: Unable to preload ${e}`,`
|
|
2
|
+
`,t)}}#f=(e,t)=>{let r=decodeURI(e.url).replace(this.#t,"").replaceAll("../","");if(r=this.#n.get(r)??l.join(this.#e,r),this.#s.has(r))return!1;if(!O.existsSync(r))return t.notFound();let{mimeType:n,isText:s}=this.#a(r),p=s?/\bbr\b/.test(e.headers["accept-encoding"])?"br":"gzip":null;t.writeHead(200,{"Content-Type":n+(s?"; charset=utf-8":""),...p&&{"Content-Encoding":p}});let a=this.#i.get(r);return a?t.end(s&&p?a[p]:a):new Promise(i=>{let c=O.createReadStream(r).on("error",()=>i(!1));p&&(c=c.pipe(k(p))),c.on("end",i),c.pipe(t)})}};function U(o){for(let e in o)o[e]===void 0&&delete o[e];return o}function y(){}function pe(o,e=0,t={}){let{leading:r=!1,trailing:n=!0}=t,{maxWait:s=1/0}=t,p,a,i,c,b,R,d,P,B=async()=>{let x=Date.now();x>=i?(p=void 0,i=void 0,clearTimeout(a),typeof d=="function"&&await d(),f.resolve(P),f.promise.isResolved=!0,R=r):(clearTimeout(p),p=setTimeout(B,i-x))},L=Number.isFinite(s)?()=>{d===h&&(d=!1),h(),a=setTimeout(L,s)}:null;async function h(){return P=await o.apply(c,b)}r&&typeof r=="boolean"&&(r=h),R=r,n&&typeof n=="boolean"&&(n=h),d=n;let f=Object.assign(function(...x){return b=x,c=this,i=Date.now()+e,d=n,f.promise.isResolved&&(f.promise=Object.assign(new Promise(ne=>{f.resolve=ne,typeof R=="function"&&(R(),R=!1,d===h&&(d=!1)),p||(p=setTimeout(B,e),L&&(a=setTimeout(L,s)))}),{isResolved:!1})),f.promise},{callback:o,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:y,run:h,clear:async x=>{clearTimeout(p),p=void 0,clearTimeout(a),f.promise.isResolved=!0,f.resolve(x?await h():P)}});return f}pe.noop=Object.assign(()=>{},{callback:y,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:y,run:y,clear:y});function q(o){for(let e in o)return!1;return!0}function G(o,e,t,r,n=!0){return Array.isArray(o)&&(o=o.length),typeof r!="string"&&(n=r??!0,r=t),(n?`${o}\xA0`:"")+G.raw(o,e,t,r)}G.raw=(o,e,t,r=t)=>{o=Math.abs(o);let n=o%10,s=o%100;return n===1&&s!==11?e:n>=2&&n<=4&&!(s>=12&&s<=15)?t:r};var{INSITE_TITLE:ue}=process.env,z={};for(let o in process.env)o.startsWith("INSITE_CLIENT_")&&(z[o.replace(/INSITE_CLIENT_/,"").toLowerCase()]=process.env[o]);var le={"Content-Type":"text/html; charset=utf-8"},F=class extends m{constructor({path:e=/.*/,globals:t={},title:r=ue??"inSite",css:n=[],rootId:s="root"}={}){super(),this.listeners={GET:[[e,this.#n]]},this.#e=r,this.#o=Array.isArray(n)?n:[n],this.#t=s,Object.assign(t,z),this.#r=`<!DOCTYPE html><html lang="ru"><head><meta charset="utf-8" /><meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" /><title>${this.#e}</title>${this.#o.map(p=>`<link rel="stylesheet" href="${p}" />`).join("")}${q(t)?"":`<script>globalThis.__insite=${JSON.stringify(t)};</script>`}<script type="text/javascript" src="/index.js" defer></script></head><body><div id="${this.#t}"></div></body></html>`}#e;#o;#t;#r;#n=(e,t)=>_(e,t,le,this.#r)};import{createServer as ge,resolveSSL as Re,showServerListeningMessage as re}from"insite-common/backend";import{IncomingMessage as de}from"node:http";import me from"node:querystring";var T=Symbol("server"),S=Symbol("request"),g=Symbol("match");var ce=/\/(?:(\*)|:([^/?]+)(\?(.*))?)/g;function Q(o,e=0){return o.replaceAll(ce,(t,r,n,s,p)=>{if(r)return`/(?<__${e++}>.*?)`;let a=`/(?<${n}>[^/]+)`;return s?`(?:${a}${p?Q(p,e):""})?`:a})}function J(o){return new RegExp(`^${o.startsWith("/")?"":"/"}${Q(o)}/?$`)}var fe=/^__/;function W(o){let e=o[g];if(e){delete o[g];let t=[void 0,...e.slice(1)];if(e.groups)for(let[r,n]of Object.entries(e.groups))t[r.replace(fe,"")]=n;return t}return[]}function K({querystring:o}){return o?.split("&").reduce((e,t)=>{let[r,n]=t.split("=");return e[r]=decodeURIComponent(n||""),e},{})??{}}function V({headers:{authorization:o}}){return o?.indexOf("Bearer ")===0?o.slice(7):null}function X(o,e){let t=e.exec(o.path);return t?(o[g]=t,!0):!1}var H=class{constructor(e){this.#e=e}#e;stream(){return this.#e}#o;text(){return new Promise((e,t)=>{if(this.#o)e(this.#o);else{let r="";this.#e.on("data",n=>{r+=n}),this.#e.on("end",()=>{e(this.#o=r)}),this.#e.on("error",t)}})}#t;async bytes(){return this.#t??=new TextEncoder().encode(await this.text()),this.#t}async arrayBuffer(){return(await this.bytes()).buffer}#r;async json(){return this.#r??=JSON.parse(await this.text()),this.#r}#n;async urlEncoded(){return this.#n=me.parse(await this.text()),this.#n}},w=class extends de{path;querystring;_addHeaderLine(e,t,r){super._addHeaderLine(e,t,r),this.path||([this.path,this.querystring]=this.url.split("?",2))}[g];#e;get params(){return this.#e??=W(this)}#o;get query(){return this.#o??=K(this)}#t;get bearer(){return this.#t??=V(this)}#r;get body(){return this.#r??=new H(this)}};import{ServerResponse as he}from"node:http";import{Readable as xe}from"node:stream";var v=class extends he{[T];[S];status(e){return this.statusCode=e,this}set(e,t){if(typeof e=="string")return this.setHeader(e,t);for(let r in e)this.setHeader(r,e[r]);return this}header=this.set;text(e,t=200){return this.writeHead(t,{"Content-Type":"text/plain; charset=utf-8","Content-Length":Buffer.byteLength(e)}).end(e)}json(e,t=200){let r=JSON.stringify(e);return this.writeHead(t,{"Content-Type":"application/json; charset=utf-8","Content-Length":Buffer.byteLength(r)}).end(r)}urlEncoded(e,t=200){let r=new URLSearchParams(e).toString();return this.writeHead(t,{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8","Content-Length":Buffer.byteLength(r)}).end(r)}stream(e,t,r=200){return typeof t=="number"&&(r=t,t=void 0),this.writeHead(r,t),e.pipe(this)}give(e,t,r=200){return typeof t=="number"&&(r=t,t=void 0),typeof e=="string"?this.text(e,r):e instanceof xe?this.stream(e,t,r):this.json(e,r)}error(e,t,{headers:r,handler:n}={}){return this[T]._throw(this,U({statusCode:e,headers:r,body:t,handler:n}))}badRequest(e){return this.error(400,e)}unauthorized(e){return this.error(401,e)}forbidden(e){return this.error(403,e)}notFound(e){return this.error(404,e)}requestTimeout(e){return this.error(408,e)}gone(e){return this.error(410,e)}internalServerError(e){return this.error(500,e)}serviceUnavailable(e){return this.error(503,e)}};var ye=["DELETE","GET","PATCH","POST","PUT"];function j(o){return ye.includes(o)||o==="ALL"}function Y(o){return Array.isArray(o)}function Z(o){return!Array.isArray(o)}function ee(o,e){return!!(o&&e[o])}function te(o){return!!o&&"emit"in o}var M=class o{constructor({port:e,ssl:t,listeners:r,errors:n,server:s},p=[]){if(te(s)?(this.server=s,new Promise(a=>void(s.listening?a():s.on("listening",a))).then(()=>re(this))):(this.server=ge(o.makeProps({ssl:t,server:s})),this.server.listen(typeof e=="string"?Number.parseInt(e):e??(this.isS?443:80),()=>re(this))),r)for(let[a,i]of Object.entries(r))for(let[c,b]of i)this.addRequestListener(a,c,b);if(n)for(let a of Object.keys(n)){let i=Number.parseInt(a);i&&(this.#t[i]?Object.assign(this.#t[i],n[i]):this.#t[i]=n[i])}if(p)for(let a of p)a&&this.addMiddleware(a);this.server.on("request",this.#o)}icon="\u{1F578}\uFE0F ";name="HTTP";get protocol(){return`http${this.isS?"s":""}`}server;get isS(){return"setSecureContext"in this.server}#e={POST:[],GET:[],PUT:[],PATCH:[],DELETE:[]};#o=async(e,t)=>{if(t[T]=this,t[S]=e,!("status"in e)&&ee(e.method,this.#e)){for(let[r,n]of this.#e[e.method])if(X(e,r)&&await n(e,t)!==!1)return}t.notFound()};#t={401:{statusCode:401,body:"Unauthorized"},403:{statusCode:403,body:"Forbidden"},404:{statusCode:404,body:"Not Found"},408:{statusCode:408,body:"Request Timeout"},410:{statusCode:410,body:"Gone"},500:{statusCode:500,body:"Internal Server Error"},503:{statusCode:503,body:"Service Unavailable"},default:{statusCode:400,body:"Bad Request",handler(e,t,{statusCode:r,headers:n,body:s}){return t.give(s,n,r)}}};_throw(e,{statusCode:t,...r}){let{handler:n,...s}={...this.#t.default,...this.#t[t],...r};return n(e[S],e,s)}addRequestListener(e,t,r){if(typeof t=="string"&&(t=J(t)),e&&e!=="ALL")this.#e[e]?.push([t,r]);else for(let n of Object.keys(this.#e))this.addRequestListener(n,t,r);return this}addMiddleware(e){if(e instanceof m){for(let[t,r]of Object.entries(e.listeners))for(let[n,s]of r)this.addRequestListener(t,n,s);e.bindTo?.(this)}else if(Y(e)){Z(e)&&(e=[e]);for(let t of e)this.addRequestListener(...t.length===2?["GET",...t]:t)}else this.#r(e);return this}#r(e,t="GET",r=""){for(let[n,s]of Object.entries(e))typeof s=="function"?j(n)?this.addRequestListener(n,r,s):this.addRequestListener(t,`${r}${n}`,s):j(n)?this.#r(s,n,r):this.#r(s,t,`${r}${n}`)}post(e,t){return this.addRequestListener("POST",e,t),this}get(e,t){return this.addRequestListener("GET",e,t),this}put(e,t){return this.addRequestListener("PUT",e,t),this}patch(e,t){return this.addRequestListener("PATCH",e,t),this}delete(e,t){return this.addRequestListener("DELETE",e,t),this}static makeProps({ssl:e,server:t}){return{...Re(e),IncomingMessage:w,ServerResponse:v,...t}}};var oe=class extends M{constructor(e,t,r=[]){super(t,[new E(e),...r])}name="Static";icon="\u{1F6D2}"};export{m as ClassMiddleware,M as HTTPServer,Se as InitialsMiddleware,E as StaticMiddleware,oe as StaticServer,F as TemplateMiddleware};
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "insite-http",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "inSite HTTPS server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
|
-
"packageManager": "bun@1.2.
|
|
8
|
+
"packageManager": "bun@1.2.5",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
11
|
"build": "bun .conveyer.js",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nesvet/n": "^1.1.
|
|
28
|
-
"insite-common": "^2.2.
|
|
27
|
+
"@nesvet/n": "^1.1.26",
|
|
28
|
+
"insite-common": "^2.2.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@nesvet/conveyer": "^2.
|
|
31
|
+
"@nesvet/conveyer": "^2.5.0",
|
|
32
32
|
"@nesvet/eslint-config": "^2.0.48",
|
|
33
|
-
"@types/node": "^22.13.
|
|
34
|
-
"typescript": "^5.
|
|
33
|
+
"@types/node": "^22.13.10",
|
|
34
|
+
"typescript": "^5.8.2"
|
|
35
35
|
}
|
|
36
36
|
}
|