rjweb-server
Advanced tools
Comparing version 2.2.7 to 2.2.8
@@ -11,2 +11,2 @@ var ye=Object.create;var ae=Object.defineProperty;var we=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var ge=Object.getPrototypeOf,be=Object.prototype.hasOwnProperty;var ve=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports);var Ee=(r,t,i,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of Te(t))!be.call(r,d)&&d!==i&&ae(r,d,{get:()=>t[d],enumerable:!(c=we(t,d))||c.enumerable});return r};var v=(r,t,i)=>(i=r!=null?ye(ge(r)):{},Ee(t||!r||!r.__esModule?ae(i,"default",{value:r,enumerable:!0}):i,r));var U=ve((Ce,ie)=>{ie.exports=["OPTIONS","DELETE","PATCH","STATIC","POST","PUT","GET"]});var I=v(require("fs")),O=(r,t)=>(t=t||[],I.readdirSync(r).forEach(c=>{if(I.statSync(r+"/"+c).isDirectory())t=O(r+"/"+c,t);else{let d=r+"/"+c;t.push(d)}}),t),ne=(r,t,i)=>(i=i||[],i=O(r,i).filter(c=>c.endsWith(t)),i);var W=v(U()),oe=v(require("path")),ce=v(require("fs")),E=r=>(r=r.replace(/\/{2,}/g,"/"),r.endsWith("/")&&r!=="/"?r.slice(0,-1):!r.startsWith("/")&&r!=="/"?`/${r}`:r),k=class{constructor(t,i){t=t!=null?t:[],i=i!=null?i:[],this.routes=t,this.events=i}event(t,i){return this.events.some(c=>c.event===t)?!1:this.events.push({event:t,code:i})-1}set(t,i,c){if(i=E(i),!W.default.includes(t))throw TypeError(`No Valid Request Type: ${t} | ||
${o}`),e.rawRes.end()}return m}}},h=he.createServer(async(u,e)=>{let m="";if(u.headers["content-length"]&&Number(u.headers["content-length"])>=L*1e6)return e.statusCode=413,e.write("Payload Too Large"),e.end();u.on("data",l=>{m+=l}).on("end",async()=>{var _,q,ee;let l={...me.parse(u.url),method:u.method};l.path=E(l.path),l.pathname=E(l.pathname);let o;try{m=JSON.parse(m)}catch(s){}if(B&&(e.setHeader("Access-Control-Allow-Headers","*"),e.setHeader("Access-Control-Allow-Origin","*"),e.setHeader("Access-Control-Request-Method","*"),e.setHeader("Access-Control-Allow-Methods",ue.default.join(",")),u.method==="OPTIONS"))return e.end("");let C=new Map,R,j=!1,Q=l.pathname.split("/");for(let s=0;s<=t.length;s++){let n=t[s];if(n.path===l.pathname&&n.method===u.method){o=s,j=!1,R=!0;break}else if(n.path===l.pathname&&n.method==="STATIC"){o=s,j=!0,R=!0;break}if(n.method===u.method&&n.pathArray.length===Q.length){if(R)break;for(let w=0;w<=n.pathArray.length;w++){let p=n.pathArray[w],b=Q[w];if(!p.startsWith(":")&&b!==p)break;if(p!==b&&p.startsWith(":")){C.set(p.replace(":",""),decodeURIComponent(b)),o=s,R=!0;continue}}}}let g;c&&u.headers["x-forwarded-for"]?g=u.headers["x-forwarded-for"]:g=u.socket.remoteAddress;let M=new Map;Object.keys(u.headers).forEach(s=>{M.set(s,u.headers[s])}),M.delete("cookie");let Y=new Map;for(let[s,n]of new URLSearchParams(l.search))Y.set(s,n);let Z=new Map;u.headers.cookie&&u.headers.cookie.split(";").forEach(s=>{let[n,...w]=s.split("=");if(n=n==null?void 0:n.trim(),!n)return;let p=w.join("=").trim();p&&Z.set(n,decodeURIComponent(p))}),N&&e.setHeader("X-Powered-By","rjweb-server");let a={headers:M,cookies:Z,params:C,queries:Y,client:{userAgent:u.headers["user-agent"],httpVersion:u.httpVersion,port:u.socket.remotePort,ip:g},body:m,url:l,rawServer:h,rawReq:u,rawRes:e,"@":{},setHeader(s,n){return e.setHeader(s,n),a},setCustom(s,n){return a["@"][s]=n,a},print(s,n){var p;let w=(p=n==null?void 0:n.niceJSON)!=null?p:!1;switch(typeof s){case"object":e.setHeader("Content-Type","application/json"),w?e.write(JSON.stringify(s,void 0,1)):e.write(JSON.stringify(s));break;case"bigint":case"number":case"boolean":e.write(s.toString());break;case"function":e.write(s());break;case"undefined":e.write("");break;default:try{e.write(s)}catch(b){a.error=b,x=!0,T("error",a)}}return a},status(s){return e.statusCode=s,a},printFile(s,n){var re,se;let w=(re=n==null?void 0:n.addTypes)!=null?re:!0,p=(se=n==null?void 0:n.cache)!=null?se:!1;if(w&&(s.endsWith(".pdf")&&a.setHeader("Content-Type","application/pdf"),s.endsWith(".js")&&a.setHeader("Content-Type","text/javascript"),s.endsWith(".html")&&a.setHeader("Content-Type","text/html"),s.endsWith(".css")&&a.setHeader("Content-Type","text/css"),s.endsWith(".csv")&&a.setHeader("Content-Type","text/csv"),s.endsWith(".mpeg")&&a.setHeader("Content-Type","video/mpeg"),s.endsWith(".mp4")&&a.setHeader("Content-Type","video/mp4"),s.endsWith(".webm")&&a.setHeader("Content-Type","video/webm"),s.endsWith(".bmp")&&a.setHeader("Content-Type","image/bmp")),S.has(s))return e.write(S.get(s),"binary"),a;let b,te=!1;try{b=$.readFileSync(s)}catch(pe){te=!0,a.error=pe,T("error",a)}return te||(p&&S.set(s,b),e.write(b,"binary")),a}},x=await T("request",a);if(!x){if(d.enabled){for(let s of d.list)if(l.path.startsWith(s.path)&&(e.setHeader("X-RateLimit-Limit",s.times),e.setHeader("X-RateLimit-Remaining",s.times-((_=await d.functions.get(g+s.path))!=null?_:0)),e.setHeader("X-RateLimit-Reset-Every",s.timeout),await d.functions.set(g+s.path,((q=await d.functions.get(g+s.path))!=null?q:0)+1),setTimeout(async()=>{var n;await d.functions.set(g+s.path,((n=await d.functions.get(g+s.path))!=null?n:0)-1)},s.timeout),await d.functions.get(g+s.path)>s.times))return e.statusCode=429,x=!0,a.print((ee=d.message)!=null?ee:"Rate Limited"),e.end()}if(R&&!x)if(!j)Promise.resolve(t[o].code(a)).catch(s=>{a.error=s,x=!0,T("error",a)}).then(()=>e.end());else{if(t[o].data.addTypes&&(t[o].path.endsWith(".pdf")&&a.setHeader("Content-Type","application/pdf"),t[o].path.endsWith(".js")&&a.setHeader("Content-Type","text/javascript"),t[o].path.endsWith(".html")&&a.setHeader("Content-Type","text/html"),t[o].path.endsWith(".css")&&a.setHeader("Content-Type","text/css"),t[o].path.endsWith(".csv")&&a.setHeader("Content-Type","text/csv"),t[o].path.endsWith(".mpeg")&&a.setHeader("Content-Type","video/mpeg"),t[o].path.endsWith(".mp4")&&a.setHeader("Content-Type","video/mp4"),t[o].path.endsWith(".webm")&&a.setHeader("Content-Type","video/webm"),t[o].path.endsWith(".bmp")&&a.setHeader("Content-Type","image/bmp")),!("content"in t[o].data)){let s=fe.resolve(t[o].data.file),n,w=!1;try{n=$.readFileSync(s)}catch(p){w=!0,a.error=p,T("error",a)}return w?void 0:(e.write(n,"binary"),e.end())}return e.write(t[o].data.content,"binary"),e.end()}else T("notfound",a)}})});return h.listen(y,f),new Promise((u,e)=>{h.once("listening",()=>u({success:!0,port:y,message:"WEBSERVER STARTED",rawServer:h})),h.once("error",m=>{h.close(),e({success:!1,error:m,message:"WEBSERVER ERRORED"})})})}}; | ||
${o}`),e.rawRes.end()}return m}}},h=he.createServer(async(u,e)=>{let m="";if(u.headers["content-length"]&&Number(u.headers["content-length"])>=L*1e6)return e.statusCode=413,e.write("Payload Too Large"),e.end();u.on("data",l=>{m+=l}).on("end",async()=>{var _,q,ee;let l={...me.parse(u.url),method:u.method};l.path=E(l.path),l.pathname=E(l.pathname);let o;try{m=JSON.parse(m)}catch(s){}if(B&&(e.setHeader("Access-Control-Allow-Headers","*"),e.setHeader("Access-Control-Allow-Origin","*"),e.setHeader("Access-Control-Request-Method","*"),e.setHeader("Access-Control-Allow-Methods",ue.default.join(",")),u.method==="OPTIONS"))return e.end("");let C=new Map,R,j=!1,Q=l.pathname.split("/");for(let s=0;s<=t.length-1;s++){let a=t[s];if(console.log(a),a.path===l.pathname&&a.method===u.method){o=s,j=!1,R=!0;break}if(a.path===l.pathname&&a.method==="STATIC"){o=s,j=!0,R=!0;break}if(a.method===u.method&&a.pathArray.length===Q.length){if(R)break;for(let w=0;w<=a.pathArray.length-1;w++){let p=a.pathArray[w],b=Q[w];if(!p.startsWith(":")&&b!==p)break;if(p!==b&&p.startsWith(":")){C.set(p.replace(":",""),decodeURIComponent(b)),o=s,R=!0;continue}}}}let g;c&&u.headers["x-forwarded-for"]?g=u.headers["x-forwarded-for"]:g=u.socket.remoteAddress;let M=new Map;Object.keys(u.headers).forEach(s=>{M.set(s,u.headers[s])}),M.delete("cookie");let Y=new Map;for(let[s,a]of new URLSearchParams(l.search))Y.set(s,a);let Z=new Map;u.headers.cookie&&u.headers.cookie.split(";").forEach(s=>{let[a,...w]=s.split("=");if(a=a==null?void 0:a.trim(),!a)return;let p=w.join("=").trim();p&&Z.set(a,decodeURIComponent(p))}),N&&e.setHeader("X-Powered-By","rjweb-server");let n={headers:M,cookies:Z,params:C,queries:Y,client:{userAgent:u.headers["user-agent"],httpVersion:u.httpVersion,port:u.socket.remotePort,ip:g},body:m,url:l,rawServer:h,rawReq:u,rawRes:e,"@":{},setHeader(s,a){return e.setHeader(s,a),n},setCustom(s,a){return n["@"][s]=a,n},print(s,a){var p;let w=(p=a==null?void 0:a.niceJSON)!=null?p:!1;switch(typeof s){case"object":e.setHeader("Content-Type","application/json"),w?e.write(JSON.stringify(s,void 0,1)):e.write(JSON.stringify(s));break;case"bigint":case"number":case"boolean":e.write(s.toString());break;case"function":e.write(s());break;case"undefined":e.write("");break;default:try{e.write(s)}catch(b){n.error=b,x=!0,T("error",n)}}return n},status(s){return e.statusCode=s,n},printFile(s,a){var re,se;let w=(re=a==null?void 0:a.addTypes)!=null?re:!0,p=(se=a==null?void 0:a.cache)!=null?se:!1;if(w&&(s.endsWith(".pdf")&&n.setHeader("Content-Type","application/pdf"),s.endsWith(".js")&&n.setHeader("Content-Type","text/javascript"),s.endsWith(".html")&&n.setHeader("Content-Type","text/html"),s.endsWith(".css")&&n.setHeader("Content-Type","text/css"),s.endsWith(".csv")&&n.setHeader("Content-Type","text/csv"),s.endsWith(".mpeg")&&n.setHeader("Content-Type","video/mpeg"),s.endsWith(".mp4")&&n.setHeader("Content-Type","video/mp4"),s.endsWith(".webm")&&n.setHeader("Content-Type","video/webm"),s.endsWith(".bmp")&&n.setHeader("Content-Type","image/bmp")),S.has(s))return e.write(S.get(s),"binary"),n;let b,te=!1;try{b=$.readFileSync(s)}catch(pe){te=!0,n.error=pe,T("error",n)}return te||(p&&S.set(s,b),e.write(b,"binary")),n}},x=await T("request",n);if(!x){if(d.enabled){for(let s of d.list)if(l.path.startsWith(s.path)&&(e.setHeader("X-RateLimit-Limit",s.times),e.setHeader("X-RateLimit-Remaining",s.times-((_=await d.functions.get(g+s.path))!=null?_:0)),e.setHeader("X-RateLimit-Reset-Every",s.timeout),await d.functions.set(g+s.path,((q=await d.functions.get(g+s.path))!=null?q:0)+1),setTimeout(async()=>{var a;await d.functions.set(g+s.path,((a=await d.functions.get(g+s.path))!=null?a:0)-1)},s.timeout),await d.functions.get(g+s.path)>s.times))return e.statusCode=429,x=!0,n.print((ee=d.message)!=null?ee:"Rate Limited"),e.end()}if(R&&!x)if(!j)Promise.resolve(t[o].code(n)).catch(s=>{n.error=s,x=!0,T("error",n)}).then(()=>e.end());else{if(t[o].data.addTypes&&(t[o].path.endsWith(".pdf")&&n.setHeader("Content-Type","application/pdf"),t[o].path.endsWith(".js")&&n.setHeader("Content-Type","text/javascript"),t[o].path.endsWith(".html")&&n.setHeader("Content-Type","text/html"),t[o].path.endsWith(".css")&&n.setHeader("Content-Type","text/css"),t[o].path.endsWith(".csv")&&n.setHeader("Content-Type","text/csv"),t[o].path.endsWith(".mpeg")&&n.setHeader("Content-Type","video/mpeg"),t[o].path.endsWith(".mp4")&&n.setHeader("Content-Type","video/mp4"),t[o].path.endsWith(".webm")&&n.setHeader("Content-Type","video/webm"),t[o].path.endsWith(".bmp")&&n.setHeader("Content-Type","image/bmp")),!("content"in t[o].data)){let s=fe.resolve(t[o].data.file),a,w=!1;try{a=$.readFileSync(s)}catch(p){w=!0,n.error=p,T("error",n)}return w?void 0:(e.write(a,"binary"),e.end())}return e.write(t[o].data.content,"binary"),e.end()}else T("notfound",n)}})});return h.listen(y,f),new Promise((u,e)=>{h.once("listening",()=>u({success:!0,port:y,message:"WEBSERVER STARTED",rawServer:h})),h.once("error",m=>{h.close(),e({success:!1,error:m,message:"WEBSERVER ERRORED"})})})}}; |
@@ -11,2 +11,2 @@ var Re=Object.create;var ae=Object.defineProperty;var Se=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var Ae=Object.getPrototypeOf,He=Object.prototype.hasOwnProperty;var ne=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,a)=>(typeof require<"u"?require:t)[a]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+e+'" is not supported')});var M=(e,t)=>()=>(e&&(t=e(e=0)),t);var ie=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var xe=(e,t,a,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of Ce(t))!He.call(e,d)&&d!==a&&ae(e,d,{get:()=>t[d],enumerable:!(c=Se(t,d))||c.enumerable});return e};var oe=(e,t,a)=>(a=e!=null?Re(Ae(e)):{},xe(t||!e||!e.__esModule?ae(a,"default",{value:e,enumerable:!0}):a,e));import*as P from"fs";var I,ce,de=M(()=>{I=(e,t)=>(t=t||[],P.readdirSync(e).forEach(c=>{if(P.statSync(e+"/"+c).isDirectory())t=I(e+"/"+c,t);else{let d=e+"/"+c;t.push(d)}}),t),ce=(e,t,a)=>(a=a||[],a=I(e,a).filter(c=>c.endsWith(t)),a)});var U=ie((Ne,le)=>{le.exports=["OPTIONS","DELETE","PATCH","STATIC","POST","PUT","GET"]});import*as ue from"path";import*as fe from"fs";var x,v,W,he=M(()=>{de();x=oe(U()),v=e=>(e=e.replace(/\/{2,}/g,"/"),e.endsWith("/")&&e!=="/"?e.slice(0,-1):!e.startsWith("/")&&e!=="/"?`/${e}`:e),W=class{constructor(t,a){t=t!=null?t:[],a=a!=null?a:[],this.routes=t,this.events=a}event(t,a){return this.events.some(c=>c.event===t)?!1:this.events.push({event:t,code:a})-1}set(t,a,c){if(a=v(a),!x.default.includes(t))throw TypeError(`No Valid Request Type: ${t} | ||
${o}`),r.rawRes.end()}return m}}},h=ge.createServer(async(u,r)=>{let m="";if(u.headers["content-length"]&&Number(u.headers["content-length"])>=k*1e6)return r.statusCode=413,r.write("Payload Too Large"),r.end();u.on("data",l=>{m+=l}).on("end",async()=>{var _,q,ee;let l={...be.parse(u.url),method:u.method};l.path=v(l.path),l.pathname=v(l.pathname);let o;try{m=JSON.parse(m)}catch(s){}if(O&&(r.setHeader("Access-Control-Allow-Headers","*"),r.setHeader("Access-Control-Allow-Origin","*"),r.setHeader("Access-Control-Request-Method","*"),r.setHeader("Access-Control-Allow-Methods",we.default.join(",")),u.method==="OPTIONS"))return r.end("");let S=new Map,E,B=!1,Q=l.pathname.split("/");for(let s=0;s<=t.length;s++){let i=t[s];if(i.path===l.pathname&&i.method===u.method){o=s,B=!1,E=!0;break}else if(i.path===l.pathname&&i.method==="STATIC"){o=s,B=!0,E=!0;break}if(i.method===u.method&&i.pathArray.length===Q.length){if(E)break;for(let w=0;w<=i.pathArray.length;w++){let p=i.pathArray[w],b=Q[w];if(!p.startsWith(":")&&b!==p)break;if(p!==b&&p.startsWith(":")){S.set(p.replace(":",""),decodeURIComponent(b)),o=s,E=!0;continue}}}}let g;c&&u.headers["x-forwarded-for"]?g=u.headers["x-forwarded-for"]:g=u.socket.remoteAddress;let j=new Map;Object.keys(u.headers).forEach(s=>{j.set(s,u.headers[s])}),j.delete("cookie");let Y=new Map;for(let[s,i]of new URLSearchParams(l.search))Y.set(s,i);let Z=new Map;u.headers.cookie&&u.headers.cookie.split(";").forEach(s=>{let[i,...w]=s.split("=");if(i=i==null?void 0:i.trim(),!i)return;let p=w.join("=").trim();p&&Z.set(i,decodeURIComponent(p))}),L&&r.setHeader("X-Powered-By","rjweb-server");let n={headers:j,cookies:Z,params:S,queries:Y,client:{userAgent:u.headers["user-agent"],httpVersion:u.httpVersion,port:u.socket.remotePort,ip:g},body:m,url:l,rawServer:h,rawReq:u,rawRes:r,"@":{},setHeader(s,i){return r.setHeader(s,i),n},setCustom(s,i){return n["@"][s]=i,n},print(s,i){var p;let w=(p=i==null?void 0:i.niceJSON)!=null?p:!1;switch(typeof s){case"object":r.setHeader("Content-Type","application/json"),w?r.write(JSON.stringify(s,void 0,1)):r.write(JSON.stringify(s));break;case"bigint":case"number":case"boolean":r.write(s.toString());break;case"function":r.write(s());break;case"undefined":r.write("");break;default:try{r.write(s)}catch(b){n.error=b,H=!0,T("error",n)}}return n},status(s){return r.statusCode=s,n},printFile(s,i){var re,se;let w=(re=i==null?void 0:i.addTypes)!=null?re:!0,p=(se=i==null?void 0:i.cache)!=null?se:!1;if(w&&(s.endsWith(".pdf")&&n.setHeader("Content-Type","application/pdf"),s.endsWith(".js")&&n.setHeader("Content-Type","text/javascript"),s.endsWith(".html")&&n.setHeader("Content-Type","text/html"),s.endsWith(".css")&&n.setHeader("Content-Type","text/css"),s.endsWith(".csv")&&n.setHeader("Content-Type","text/csv"),s.endsWith(".mpeg")&&n.setHeader("Content-Type","video/mpeg"),s.endsWith(".mp4")&&n.setHeader("Content-Type","video/mp4"),s.endsWith(".webm")&&n.setHeader("Content-Type","video/webm"),s.endsWith(".bmp")&&n.setHeader("Content-Type","image/bmp")),R.has(s))return r.write(R.get(s),"binary"),n;let b,te=!1;try{b=$.readFileSync(s)}catch(Ee){te=!0,n.error=Ee,T("error",n)}return te||(p&&R.set(s,b),r.write(b,"binary")),n}},H=await T("request",n);if(!H){if(d.enabled){for(let s of d.list)if(l.path.startsWith(s.path)&&(r.setHeader("X-RateLimit-Limit",s.times),r.setHeader("X-RateLimit-Remaining",s.times-((_=await d.functions.get(g+s.path))!=null?_:0)),r.setHeader("X-RateLimit-Reset-Every",s.timeout),await d.functions.set(g+s.path,((q=await d.functions.get(g+s.path))!=null?q:0)+1),setTimeout(async()=>{var i;await d.functions.set(g+s.path,((i=await d.functions.get(g+s.path))!=null?i:0)-1)},s.timeout),await d.functions.get(g+s.path)>s.times))return r.statusCode=429,H=!0,n.print((ee=d.message)!=null?ee:"Rate Limited"),r.end()}if(E&&!H)if(!B)Promise.resolve(t[o].code(n)).catch(s=>{n.error=s,H=!0,T("error",n)}).then(()=>r.end());else{if(t[o].data.addTypes&&(t[o].path.endsWith(".pdf")&&n.setHeader("Content-Type","application/pdf"),t[o].path.endsWith(".js")&&n.setHeader("Content-Type","text/javascript"),t[o].path.endsWith(".html")&&n.setHeader("Content-Type","text/html"),t[o].path.endsWith(".css")&&n.setHeader("Content-Type","text/css"),t[o].path.endsWith(".csv")&&n.setHeader("Content-Type","text/csv"),t[o].path.endsWith(".mpeg")&&n.setHeader("Content-Type","video/mpeg"),t[o].path.endsWith(".mp4")&&n.setHeader("Content-Type","video/mp4"),t[o].path.endsWith(".webm")&&n.setHeader("Content-Type","video/webm"),t[o].path.endsWith(".bmp")&&n.setHeader("Content-Type","image/bmp")),!("content"in t[o].data)){let s=Te.resolve(t[o].data.file),i,w=!1;try{i=$.readFileSync(s)}catch(p){w=!0,n.error=p,T("error",n)}return w?void 0:(r.write(i,"binary"),r.end())}return r.write(t[o].data.content,"binary"),r.end()}else T("notfound",n)}})});return h.listen(y,f),new Promise((u,r)=>{h.once("listening",()=>u({success:!0,port:y,message:"WEBSERVER STARTED",rawServer:h})),h.once("error",m=>{h.close(),r({success:!1,error:m,message:"WEBSERVER ERRORED"})})})}}});export default We(); | ||
${o}`),r.rawRes.end()}return m}}},h=ge.createServer(async(u,r)=>{let m="";if(u.headers["content-length"]&&Number(u.headers["content-length"])>=k*1e6)return r.statusCode=413,r.write("Payload Too Large"),r.end();u.on("data",l=>{m+=l}).on("end",async()=>{var _,q,ee;let l={...be.parse(u.url),method:u.method};l.path=v(l.path),l.pathname=v(l.pathname);let o;try{m=JSON.parse(m)}catch(s){}if(O&&(r.setHeader("Access-Control-Allow-Headers","*"),r.setHeader("Access-Control-Allow-Origin","*"),r.setHeader("Access-Control-Request-Method","*"),r.setHeader("Access-Control-Allow-Methods",we.default.join(",")),u.method==="OPTIONS"))return r.end("");let S=new Map,E,B=!1,Q=l.pathname.split("/");for(let s=0;s<=t.length-1;s++){let n=t[s];if(console.log(n),n.path===l.pathname&&n.method===u.method){o=s,B=!1,E=!0;break}if(n.path===l.pathname&&n.method==="STATIC"){o=s,B=!0,E=!0;break}if(n.method===u.method&&n.pathArray.length===Q.length){if(E)break;for(let w=0;w<=n.pathArray.length-1;w++){let p=n.pathArray[w],b=Q[w];if(!p.startsWith(":")&&b!==p)break;if(p!==b&&p.startsWith(":")){S.set(p.replace(":",""),decodeURIComponent(b)),o=s,E=!0;continue}}}}let g;c&&u.headers["x-forwarded-for"]?g=u.headers["x-forwarded-for"]:g=u.socket.remoteAddress;let j=new Map;Object.keys(u.headers).forEach(s=>{j.set(s,u.headers[s])}),j.delete("cookie");let Y=new Map;for(let[s,n]of new URLSearchParams(l.search))Y.set(s,n);let Z=new Map;u.headers.cookie&&u.headers.cookie.split(";").forEach(s=>{let[n,...w]=s.split("=");if(n=n==null?void 0:n.trim(),!n)return;let p=w.join("=").trim();p&&Z.set(n,decodeURIComponent(p))}),L&&r.setHeader("X-Powered-By","rjweb-server");let i={headers:j,cookies:Z,params:S,queries:Y,client:{userAgent:u.headers["user-agent"],httpVersion:u.httpVersion,port:u.socket.remotePort,ip:g},body:m,url:l,rawServer:h,rawReq:u,rawRes:r,"@":{},setHeader(s,n){return r.setHeader(s,n),i},setCustom(s,n){return i["@"][s]=n,i},print(s,n){var p;let w=(p=n==null?void 0:n.niceJSON)!=null?p:!1;switch(typeof s){case"object":r.setHeader("Content-Type","application/json"),w?r.write(JSON.stringify(s,void 0,1)):r.write(JSON.stringify(s));break;case"bigint":case"number":case"boolean":r.write(s.toString());break;case"function":r.write(s());break;case"undefined":r.write("");break;default:try{r.write(s)}catch(b){i.error=b,H=!0,T("error",i)}}return i},status(s){return r.statusCode=s,i},printFile(s,n){var re,se;let w=(re=n==null?void 0:n.addTypes)!=null?re:!0,p=(se=n==null?void 0:n.cache)!=null?se:!1;if(w&&(s.endsWith(".pdf")&&i.setHeader("Content-Type","application/pdf"),s.endsWith(".js")&&i.setHeader("Content-Type","text/javascript"),s.endsWith(".html")&&i.setHeader("Content-Type","text/html"),s.endsWith(".css")&&i.setHeader("Content-Type","text/css"),s.endsWith(".csv")&&i.setHeader("Content-Type","text/csv"),s.endsWith(".mpeg")&&i.setHeader("Content-Type","video/mpeg"),s.endsWith(".mp4")&&i.setHeader("Content-Type","video/mp4"),s.endsWith(".webm")&&i.setHeader("Content-Type","video/webm"),s.endsWith(".bmp")&&i.setHeader("Content-Type","image/bmp")),R.has(s))return r.write(R.get(s),"binary"),i;let b,te=!1;try{b=$.readFileSync(s)}catch(Ee){te=!0,i.error=Ee,T("error",i)}return te||(p&&R.set(s,b),r.write(b,"binary")),i}},H=await T("request",i);if(!H){if(d.enabled){for(let s of d.list)if(l.path.startsWith(s.path)&&(r.setHeader("X-RateLimit-Limit",s.times),r.setHeader("X-RateLimit-Remaining",s.times-((_=await d.functions.get(g+s.path))!=null?_:0)),r.setHeader("X-RateLimit-Reset-Every",s.timeout),await d.functions.set(g+s.path,((q=await d.functions.get(g+s.path))!=null?q:0)+1),setTimeout(async()=>{var n;await d.functions.set(g+s.path,((n=await d.functions.get(g+s.path))!=null?n:0)-1)},s.timeout),await d.functions.get(g+s.path)>s.times))return r.statusCode=429,H=!0,i.print((ee=d.message)!=null?ee:"Rate Limited"),r.end()}if(E&&!H)if(!B)Promise.resolve(t[o].code(i)).catch(s=>{i.error=s,H=!0,T("error",i)}).then(()=>r.end());else{if(t[o].data.addTypes&&(t[o].path.endsWith(".pdf")&&i.setHeader("Content-Type","application/pdf"),t[o].path.endsWith(".js")&&i.setHeader("Content-Type","text/javascript"),t[o].path.endsWith(".html")&&i.setHeader("Content-Type","text/html"),t[o].path.endsWith(".css")&&i.setHeader("Content-Type","text/css"),t[o].path.endsWith(".csv")&&i.setHeader("Content-Type","text/csv"),t[o].path.endsWith(".mpeg")&&i.setHeader("Content-Type","video/mpeg"),t[o].path.endsWith(".mp4")&&i.setHeader("Content-Type","video/mp4"),t[o].path.endsWith(".webm")&&i.setHeader("Content-Type","video/webm"),t[o].path.endsWith(".bmp")&&i.setHeader("Content-Type","image/bmp")),!("content"in t[o].data)){let s=Te.resolve(t[o].data.file),n,w=!1;try{n=$.readFileSync(s)}catch(p){w=!0,i.error=p,T("error",i)}return w?void 0:(r.write(n,"binary"),r.end())}return r.write(t[o].data.content,"binary"),r.end()}else T("notfound",i)}})});return h.listen(y,f),new Promise((u,r)=>{h.once("listening",()=>u({success:!0,port:y,message:"WEBSERVER STARTED",rawServer:h})),h.once("error",m=>{h.close(),r({success:!1,error:m,message:"WEBSERVER ERRORED"})})})}}});export default We(); |
{ | ||
"name": "rjweb-server", | ||
"version": "2.2.7", | ||
"version": "2.2.8", | ||
"description": "Easy and Lightweight Way to create a Web Server with Many Features", | ||
@@ -5,0 +5,0 @@ "module": "lib/esm/index.js", |
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
57026