diesel-core 1.5.5 → 1.5.7
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/ctx.d.ts +5 -4
- package/dist/ctx.js +33 -33
- package/dist/handleRequest.js +20 -20
- package/dist/main.d.ts +11 -8
- package/dist/main.js +66 -66
- package/dist/middlewares/logger/logger.js +1 -1
- package/dist/request_pipeline.js +67 -67
- package/dist/router/regex.d.ts +2 -0
- package/dist/types.d.ts +13 -10
- package/dist/utils/request.util.js +1 -1
- package/package.json +1 -1
package/dist/ctx.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ import { Server } from "bun";
|
|
|
2
2
|
import type { ContextType, CookieOptions } from "./types";
|
|
3
3
|
export declare class Context implements ContextType {
|
|
4
4
|
req: Request;
|
|
5
|
-
server
|
|
6
|
-
|
|
5
|
+
server?: Server | undefined;
|
|
6
|
+
path?: string | undefined;
|
|
7
7
|
routePattern?: string;
|
|
8
|
+
env?: Record<string, any>;
|
|
9
|
+
executionCtx?: any | undefined;
|
|
8
10
|
headers: Headers;
|
|
9
11
|
private parsedQuery;
|
|
10
12
|
private parsedParams;
|
|
@@ -12,7 +14,7 @@ export declare class Context implements ContextType {
|
|
|
12
14
|
private parsedBody;
|
|
13
15
|
private contextData;
|
|
14
16
|
private urlObject;
|
|
15
|
-
constructor(req: Request, server
|
|
17
|
+
constructor(req: Request, server?: Server, path?: string, routePattern?: string, env?: Record<string, any>, executionCtx?: any);
|
|
16
18
|
setHeader(key: string, value: string): this;
|
|
17
19
|
removeHeader(key: string): this;
|
|
18
20
|
set<T>(key: string, value: T): this;
|
|
@@ -33,5 +35,4 @@ export declare class Context implements ContextType {
|
|
|
33
35
|
stream(callback: (controller: ReadableStreamDefaultController) => void): Response;
|
|
34
36
|
yieldStream(callback: () => AsyncIterable<any>): Response;
|
|
35
37
|
}
|
|
36
|
-
export default function createCtx(req: Request, server: Server, pathname: string, routePattern: string | undefined): ContextType;
|
|
37
38
|
export declare function extractDynamicParams(originalPath: string, incomingPath: string): Record<string, string> | null;
|
package/dist/ctx.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var U1=Object.create;var{getPrototypeOf:W1,defineProperty:B,getOwnPropertyNames:r,getOwnPropertyDescriptor:M1}=Object,u=Object.prototype.hasOwnProperty;var H1=(f,v,g)=>{g=f!=null?U1(W1(f)):{};let C=v||!f||!f.__esModule?B(g,"default",{value:f,enumerable:!0}):g;for(let A of r(f))if(!u.call(C,A))B(C,A,{get:()=>f[A],enumerable:!0});return C},E=new WeakMap,q1=(f)=>{var v=E.get(f),g;if(v)return v;if(v=B({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")r(f).map((C)=>!u.call(v,C)&&B(v,C,{get:()=>f[C],enumerable:!(g=M1(f,C))||g.enumerable}));return E.set(f,v),v},F=(f,v)=>()=>(v||f((v={exports:{}}).exports,v),v.exports);var N1=(f,v)=>{for(var g in v)B(f,g,{get:v[g],enumerable:!0,configurable:!0,set:(C)=>v[g]=()=>C})};var F1=(f,v)=>()=>(f&&(v=f(f=0)),v);var y1=((f)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(f,{get:(v,g)=>(typeof require!=="undefined"?require:v)[g]}):f)(function(f){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+f+'" is not supported')});var p={};N1(p,{sep:()=>s,resolve:()=>M,relative:()=>h,posix:()=>o,parse:()=>e,normalize:()=>y,join:()=>T,isAbsolute:()=>P,format:()=>i,extname:()=>n,dirname:()=>m,delimiter:()=>a,default:()=>R1,basename:()=>l,_makeLong:()=>d});function Q(f){if(typeof f!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function c(f,v){var g="",C=0,A=-1,b=0,w;for(var j=0;j<=f.length;++j){if(j<f.length)w=f.charCodeAt(j);else if(w===47)break;else w=47;if(w===47){if(A===j-1||b===1);else if(A!==j-1&&b===2){if(g.length<2||C!==2||g.charCodeAt(g.length-1)!==46||g.charCodeAt(g.length-2)!==46){if(g.length>2){var K=g.lastIndexOf("/");if(K!==g.length-1){if(K===-1)g="",C=0;else g=g.slice(0,K),C=g.length-1-g.lastIndexOf("/");A=j,b=0;continue}}else if(g.length===2||g.length===1){g="",C=0,A=j,b=0;continue}}if(v){if(g.length>0)g+="/..";else g="..";C=2}}else{if(g.length>0)g+="/"+f.slice(A+1,j);else g=f.slice(A+1,j);C=j-A-1}A=j,b=0}else if(w===46&&b!==-1)++b;else b=-1}return g}function D1(f,v){var g=v.dir||v.root,C=v.base||(v.name||"")+(v.ext||"");if(!g)return C;if(g===v.root)return g+C;return g+f+C}function M(){var f="",v=!1,g;for(var C=arguments.length-1;C>=-1&&!v;C--){var A;if(C>=0)A=arguments[C];else{if(g===void 0)g=process.cwd();A=g}if(Q(A),A.length===0)continue;f=A+"/"+f,v=A.charCodeAt(0)===47}if(f=c(f,!v),v)if(f.length>0)return"/"+f;else return"/";else if(f.length>0)return f;else return"."}function y(f){if(Q(f),f.length===0)return".";var v=f.charCodeAt(0)===47,g=f.charCodeAt(f.length-1)===47;if(f=c(f,!v),f.length===0&&!v)f=".";if(f.length>0&&g)f+="/";if(v)return"/"+f;return f}function P(f){return Q(f),f.length>0&&f.charCodeAt(0)===47}function T(){if(arguments.length===0)return".";var f;for(var v=0;v<arguments.length;++v){var g=arguments[v];if(Q(g),g.length>0)if(f===void 0)f=g;else f+="/"+g}if(f===void 0)return".";return y(f)}function h(f,v){if(Q(f),Q(v),f===v)return"";if(f=M(f),v=M(v),f===v)return"";var g=1;for(;g<f.length;++g)if(f.charCodeAt(g)!==47)break;var C=f.length,A=C-g,b=1;for(;b<v.length;++b)if(v.charCodeAt(b)!==47)break;var w=v.length,j=w-b,K=A<j?A:j,Y=-1,z=0;for(;z<=K;++z){if(z===K){if(j>K){if(v.charCodeAt(b+z)===47)return v.slice(b+z+1);else if(z===0)return v.slice(b+z)}else if(A>K){if(f.charCodeAt(g+z)===47)Y=z;else if(z===0)Y=0}break}var V=f.charCodeAt(g+z),G=v.charCodeAt(b+z);if(V!==G)break;else if(V===47)Y=z}var X="";for(z=g+Y+1;z<=C;++z)if(z===C||f.charCodeAt(z)===47)if(X.length===0)X+="..";else X+="/..";if(X.length>0)return X+v.slice(b+Y);else{if(b+=Y,v.charCodeAt(b)===47)++b;return v.slice(b)}}function d(f){return f}function m(f){if(Q(f),f.length===0)return".";var v=f.charCodeAt(0),g=v===47,C=-1,A=!0;for(var b=f.length-1;b>=1;--b)if(v=f.charCodeAt(b),v===47){if(!A){C=b;break}}else A=!1;if(C===-1)return g?"/":".";if(g&&C===1)return"//";return f.slice(0,C)}function l(f,v){if(v!==void 0&&typeof v!=="string")throw new TypeError('"ext" argument must be a string');Q(f);var g=0,C=-1,A=!0,b;if(v!==void 0&&v.length>0&&v.length<=f.length){if(v.length===f.length&&v===f)return"";var w=v.length-1,j=-1;for(b=f.length-1;b>=0;--b){var K=f.charCodeAt(b);if(K===47){if(!A){g=b+1;break}}else{if(j===-1)A=!1,j=b+1;if(w>=0)if(K===v.charCodeAt(w)){if(--w===-1)C=b}else w=-1,C=j}}if(g===C)C=j;else if(C===-1)C=f.length;return f.slice(g,C)}else{for(b=f.length-1;b>=0;--b)if(f.charCodeAt(b)===47){if(!A){g=b+1;break}}else if(C===-1)A=!1,C=b+1;if(C===-1)return"";return f.slice(g,C)}}function n(f){Q(f);var v=-1,g=0,C=-1,A=!0,b=0;for(var w=f.length-1;w>=0;--w){var j=f.charCodeAt(w);if(j===47){if(!A){g=w+1;break}continue}if(C===-1)A=!1,C=w+1;if(j===46){if(v===-1)v=w;else if(b!==1)b=1}else if(v!==-1)b=-1}if(v===-1||C===-1||b===0||b===1&&v===C-1&&v===g+1)return"";return f.slice(v,C)}function i(f){if(f===null||typeof f!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof f);return D1("/",f)}function e(f){Q(f);var v={root:"",dir:"",base:"",ext:"",name:""};if(f.length===0)return v;var g=f.charCodeAt(0),C=g===47,A;if(C)v.root="/",A=1;else A=0;var b=-1,w=0,j=-1,K=!0,Y=f.length-1,z=0;for(;Y>=A;--Y){if(g=f.charCodeAt(Y),g===47){if(!K){w=Y+1;break}continue}if(j===-1)K=!1,j=Y+1;if(g===46){if(b===-1)b=Y;else if(z!==1)z=1}else if(b!==-1)z=-1}if(b===-1||j===-1||z===0||z===1&&b===j-1&&b===w+1){if(j!==-1)if(w===0&&C)v.base=v.name=f.slice(1,j);else v.base=v.name=f.slice(w,j)}else{if(w===0&&C)v.name=f.slice(1,b),v.base=f.slice(1,j);else v.name=f.slice(w,b),v.base=f.slice(w,j);v.ext=f.slice(b,j)}if(w>0)v.dir=f.slice(0,w-1);else if(C)v.dir="/";return v}var s="/",a=":",o,R1;var t=F1(()=>{o=((f)=>(f.posix=f,f))({resolve:M,normalize:y,isAbsolute:P,join:T,relative:h,_makeLong:d,dirname:m,basename:l,extname:n,format:i,parse:e,sep:s,delimiter:a,win32:null,posix:null}),R1=o});var v1=F((E1)=>{var L1=/[|\\{}()[\]^$+*?.]/g,O1=Object.prototype.hasOwnProperty,R=function(f,v){return O1.apply(f,[v])};E1.escapeRegExpChars=function(f){if(!f)return"";return String(f).replace(L1,"\\$&")};var k1={"&":"&","<":"<",">":">",'"':""","'":"'"},x1=/[&<>'"]/g;function I1(f){return k1[f]||f}var S1=`var _ENCODE_HTML_RULES = {
|
|
2
2
|
"&": "&"
|
|
3
3
|
, "<": "<"
|
|
4
4
|
, ">": ">"
|
|
@@ -9,46 +9,46 @@ var N1=Object.create;var{getPrototypeOf:F1,defineProperty:W,getOwnPropertyNames:
|
|
|
9
9
|
function encode_char(c) {
|
|
10
10
|
return _ENCODE_HTML_RULES[c] || c;
|
|
11
11
|
};
|
|
12
|
-
`;
|
|
13
|
-
`+
|
|
14
|
-
`),
|
|
15
|
-
`);throw f.path
|
|
16
|
-
`+
|
|
12
|
+
`;E1.escapeXML=function(f){return f==null?"":String(f).replace(x1,I1)};function f1(){return Function.prototype.toString.call(this)+`;
|
|
13
|
+
`+S1}try{if(typeof Object.defineProperty==="function")Object.defineProperty(E1.escapeXML,"toString",{value:f1});else E1.escapeXML.toString=f1}catch(f){console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)")}E1.shallowCopy=function(f,v){if(v=v||{},f!==null&&f!==void 0)for(var g in v){if(!R(v,g))continue;if(g==="__proto__"||g==="constructor")continue;f[g]=v[g]}return f};E1.shallowCopyFromList=function(f,v,g){if(g=g||[],v=v||{},f!==null&&f!==void 0)for(var C=0;C<g.length;C++){var A=g[C];if(typeof v[A]!="undefined"){if(!R(v,A))continue;if(A==="__proto__"||A==="constructor")continue;f[A]=v[A]}}return f};E1.cache={_data:{},set:function(f,v){this._data[f]=v},get:function(f){return this._data[f]},remove:function(f){delete this._data[f]},reset:function(){this._data={}}};E1.hyphenToCamel=function(f){return f.replace(/-[a-z]/g,function(v){return v[1].toUpperCase()})};E1.createNullProtoObjWherePossible=function(){if(typeof Object.create=="function")return function(){return Object.create(null)};if(!({__proto__:null}instanceof Object))return function(){return{__proto__:null}};return function(){return{}}}();E1.hasOwnOnlyObject=function(f){var v=E1.createNullProtoObjWherePossible();for(var g in f)if(R(f,g))v[g]=f[g];return v}});var C1=F((V0,h1)=>{h1.exports={name:"ejs",description:"Embedded JavaScript templates",keywords:["template","engine","ejs"],version:"3.1.10",author:"Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",license:"Apache-2.0",bin:{ejs:"./bin/cli.js"},main:"./lib/ejs.js",jsdelivr:"ejs.min.js",unpkg:"ejs.min.js",repository:{type:"git",url:"git://github.com/mde/ejs.git"},bugs:"https://github.com/mde/ejs/issues",homepage:"https://github.com/mde/ejs",dependencies:{jake:"^10.8.5"},devDependencies:{browserify:"^16.5.1",eslint:"^6.8.0","git-directory-deploy":"^1.5.1",jsdoc:"^4.0.2","lru-cache":"^4.0.1",mocha:"^10.2.0","uglify-js":"^3.3.16"},engines:{node:">=0.10.0"},scripts:{test:"npx jake test"}}});var G1=F(($1)=>{var k=(()=>({})),U=(t(),q1(p)),Z=v1(),A1=!1,d1=C1().version,m1="<",l1=">",n1="%",Y1="locals",i1="ejs",e1="(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)",Z1=["delimiter","scope","context","debug","compileDebug","client","_with","rmWhitespace","strict","filename","async"],s1=Z1.concat("cache"),b1=/^\uFEFF/,L=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/;$1.cache=Z.cache;$1.fileLoader=k.readFileSync;$1.localsName=Y1;$1.promiseImpl=new Function("return this;")().Promise;$1.resolveInclude=function(f,v,g){var{dirname:C,extname:A,resolve:b}=U,w=b(g?v:C(v),f),j=A(f);if(!j)w+=".ejs";return w};function w1(f,v){var g;if(v.some(function(C){return g=$1.resolveInclude(f,C,!0),k.existsSync(g)}))return g}function a1(f,v){var g,C,A=v.views,b=/^[A-Za-z]+:\\|^\//.exec(f);if(b&&b.length)if(f=f.replace(/^\/*/,""),Array.isArray(v.root))g=w1(f,v.root);else g=$1.resolveInclude(f,v.root||"/",!0);else{if(v.filename){if(C=$1.resolveInclude(f,v.filename),k.existsSync(C))g=C}if(!g&&Array.isArray(A))g=w1(f,A);if(!g&&typeof v.includer!=="function")throw new Error('Could not find the include file "'+v.escapeFunction(f)+'"')}return g}function W(f,v){var g,C=f.filename,A=arguments.length>1;if(f.cache){if(!C)throw new Error("cache option requires a filename");if(g=$1.cache.get(C),g)return g;if(!A)v=j1(C).toString().replace(b1,"")}else if(!A){if(!C)throw new Error("Internal EJS error: no file name or template provided");v=j1(C).toString().replace(b1,"")}if(g=$1.compile(v,f),f.cache)$1.cache.set(C,g);return g}function o1(f,v,g){var C;if(!g)if(typeof $1.promiseImpl=="function")return new $1.promiseImpl(function(A,b){try{C=W(f)(v),A(C)}catch(w){b(w)}});else throw new Error("Please provide a callback function");else{try{C=W(f)(v)}catch(A){return g(A)}g(null,C)}}function j1(f){return $1.fileLoader(f)}function p1(f,v){var g=Z.shallowCopy(Z.createNullProtoObjWherePossible(),v);if(g.filename=a1(f,g),typeof v.includer==="function"){var C=v.includer(f,g.filename);if(C){if(C.filename)g.filename=C.filename;if(C.template)return W(g,C.template)}}return W(g)}function z1(f,v,g,C,A){var b=v.split(`
|
|
14
|
+
`),w=Math.max(C-3,0),j=Math.min(b.length,C+3),K=A(g),Y=b.slice(w,j).map(function(z,V){var G=V+w+1;return(G==C?" >> ":" ")+G+"| "+z}).join(`
|
|
15
|
+
`);throw f.path=K,f.message=(K||"ejs")+":"+C+`
|
|
16
|
+
`+Y+`
|
|
17
17
|
|
|
18
|
-
`+f.message,f}function
|
|
18
|
+
`+f.message,f}function K1(f){return f.replace(/;(\s*$)/,"$1")}$1.compile=function f(v,g){var C;if(g&&g.scope){if(!A1)console.warn("`scope` option is deprecated and will be removed in EJS 3"),A1=!0;if(!g.context)g.context=g.scope;delete g.scope}return C=new $(v,g),C.compile()};$1.render=function(f,v,g){var C=v||Z.createNullProtoObjWherePossible(),A=g||Z.createNullProtoObjWherePossible();if(arguments.length==2)Z.shallowCopyFromList(A,C,Z1);return W(A,f)(C)};$1.renderFile=function(){var f=Array.prototype.slice.call(arguments),v=f.shift(),g,C={filename:v},A,b;if(typeof arguments[arguments.length-1]=="function")g=f.pop();if(f.length){if(A=f.shift(),f.length)Z.shallowCopy(C,f.pop());else{if(A.settings){if(A.settings.views)C.views=A.settings.views;if(A.settings["view cache"])C.cache=!0;if(b=A.settings["view options"],b)Z.shallowCopy(C,b)}Z.shallowCopyFromList(C,A,s1)}C.filename=v}else A=Z.createNullProtoObjWherePossible();return o1(C,A,g)};$1.Template=$;$1.clearCache=function(){$1.cache.reset()};function $(f,v){var g=Z.hasOwnOnlyObject(v),C=Z.createNullProtoObjWherePossible();if(this.templateText=f,this.mode=null,this.truncate=!1,this.currentLine=1,this.source="",C.client=g.client||!1,C.escapeFunction=g.escape||g.escapeFunction||Z.escapeXML,C.compileDebug=g.compileDebug!==!1,C.debug=!!g.debug,C.filename=g.filename,C.openDelimiter=g.openDelimiter||$1.openDelimiter||m1,C.closeDelimiter=g.closeDelimiter||$1.closeDelimiter||l1,C.delimiter=g.delimiter||$1.delimiter||n1,C.strict=g.strict||!1,C.context=g.context,C.cache=g.cache||!1,C.rmWhitespace=g.rmWhitespace,C.root=g.root,C.includer=g.includer,C.outputFunctionName=g.outputFunctionName,C.localsName=g.localsName||$1.localsName||Y1,C.views=g.views,C.async=g.async,C.destructuredLocals=g.destructuredLocals,C.legacyInclude=typeof g.legacyInclude!="undefined"?!!g.legacyInclude:!0,C.strict)C._with=!1;else C._with=typeof g._with!="undefined"?g._with:!0;this.opts=C,this.regex=this.createRegex()}$.modes={EVAL:"eval",ESCAPED:"escaped",RAW:"raw",COMMENT:"comment",LITERAL:"literal"};$.prototype={createRegex:function(){var f=e1,v=Z.escapeRegExpChars(this.opts.delimiter),g=Z.escapeRegExpChars(this.opts.openDelimiter),C=Z.escapeRegExpChars(this.opts.closeDelimiter);return f=f.replace(/%/g,v).replace(/</g,g).replace(/>/g,C),new RegExp(f)},compile:function(){var f,v,g=this.opts,C="",A="",b=g.escapeFunction,w,j=g.filename?JSON.stringify(g.filename):"undefined";if(!this.source){if(this.generateSource(),C+=` var __output = "";
|
|
19
19
|
function __append(s) { if (s !== undefined && s !== null) __output += s }
|
|
20
|
-
`,g.outputFunctionName){if(!
|
|
21
|
-
`}if(g.localsName&&!
|
|
22
|
-
`;for(var
|
|
23
|
-
|
|
24
|
-
`}if(g._with!==!1)
|
|
25
|
-
`,
|
|
26
|
-
`;
|
|
27
|
-
`,this.source=
|
|
20
|
+
`,g.outputFunctionName){if(!L.test(g.outputFunctionName))throw new Error("outputFunctionName is not a valid JS identifier.");C+=" var "+g.outputFunctionName+` = __append;
|
|
21
|
+
`}if(g.localsName&&!L.test(g.localsName))throw new Error("localsName is not a valid JS identifier.");if(g.destructuredLocals&&g.destructuredLocals.length){var K=" var __locals = ("+g.localsName+` || {}),
|
|
22
|
+
`;for(var Y=0;Y<g.destructuredLocals.length;Y++){var z=g.destructuredLocals[Y];if(!L.test(z))throw new Error("destructuredLocals["+Y+"] is not a valid JS identifier.");if(Y>0)K+=`,
|
|
23
|
+
`;K+=z+" = __locals."+z}C+=K+`;
|
|
24
|
+
`}if(g._with!==!1)C+=" with ("+g.localsName+` || {}) {
|
|
25
|
+
`,A+=` }
|
|
26
|
+
`;A+=` return __output;
|
|
27
|
+
`,this.source=C+this.source+A}if(g.compileDebug)f=`var __line = 1
|
|
28
28
|
, __lines = `+JSON.stringify(this.templateText)+`
|
|
29
|
-
, __filename = `+
|
|
29
|
+
, __filename = `+j+`;
|
|
30
30
|
try {
|
|
31
31
|
`+this.source+`} catch (e) {
|
|
32
32
|
rethrow(e, __lines, __filename, __line, escapeFn);
|
|
33
33
|
}
|
|
34
|
-
`;else f=this.source;if(g.client){if(f="escapeFn = escapeFn || "+
|
|
35
|
-
`+f,g.compileDebug)f="rethrow = rethrow || "+
|
|
34
|
+
`;else f=this.source;if(g.client){if(f="escapeFn = escapeFn || "+b.toString()+`;
|
|
35
|
+
`+f,g.compileDebug)f="rethrow = rethrow || "+z1.toString()+`;
|
|
36
36
|
`+f}if(g.strict)f=`"use strict";
|
|
37
37
|
`+f;if(g.debug)console.log(f);if(g.compileDebug&&g.filename)f=f+`
|
|
38
|
-
//# sourceURL=`+
|
|
39
|
-
`;try{if(g.async)try{
|
|
38
|
+
//# sourceURL=`+j+`
|
|
39
|
+
`;try{if(g.async)try{w=new Function("return (async function(){}).constructor;")()}catch(J){if(J instanceof SyntaxError)throw new Error("This environment does not support async/await");else throw J}else w=Function;v=new w(g.localsName+", escapeFn, include, rethrow",f)}catch(J){if(J instanceof SyntaxError){if(g.filename)J.message+=" in "+g.filename;if(J.message+=` while compiling ejs
|
|
40
40
|
|
|
41
|
-
`,
|
|
42
|
-
`,
|
|
43
|
-
`,
|
|
44
|
-
`).replace(/^\s+|\s+$/gm,"");this.templateText=this.templateText.replace(/[ \t]*<%_/gm,"<%_").replace(/_%>[ \t]*/gm,"_%>");var v=this,g=this.parseTemplateText(),
|
|
45
|
-
`},scanLine:function(f){var v=this,g=this.opts.delimiter,
|
|
46
|
-
`).length-1,f){case
|
|
47
|
-
`;break;case g+g+
|
|
48
|
-
`;break;case g+
|
|
41
|
+
`,J.message+=`If the above error is not helpful, you may want to try EJS-Lint:
|
|
42
|
+
`,J.message+="https://github.com/RyanZim/EJS-Lint",!g.async)J.message+=`
|
|
43
|
+
`,J.message+="Or, if you meant to create an async function, pass `async: true` as an option."}throw J}var V=g.client?v:function J(I){var X1=function(B1,S){var N=Z.shallowCopy(Z.createNullProtoObjWherePossible(),I);if(S)N=Z.shallowCopy(N,S);return p1(B1,g)(N)};return v.apply(g.context,[I||Z.createNullProtoObjWherePossible(),b,X1,z1])};if(g.filename&&typeof Object.defineProperty==="function"){var G=g.filename,X=U.basename(G,U.extname(G));try{Object.defineProperty(V,"name",{value:X,writable:!1,enumerable:!1,configurable:!0})}catch(J){}}return V},generateSource:function(){var f=this.opts;if(f.rmWhitespace)this.templateText=this.templateText.replace(/[\r\n]+/g,`
|
|
44
|
+
`).replace(/^\s+|\s+$/gm,"");this.templateText=this.templateText.replace(/[ \t]*<%_/gm,"<%_").replace(/_%>[ \t]*/gm,"_%>");var v=this,g=this.parseTemplateText(),C=this.opts.delimiter,A=this.opts.openDelimiter,b=this.opts.closeDelimiter;if(g&&g.length)g.forEach(function(w,j){var K;if(w.indexOf(A+C)===0&&w.indexOf(A+C+C)!==0){if(K=g[j+2],!(K==C+b||K=="-"+C+b||K=="_"+C+b))throw new Error('Could not find matching close tag for "'+w+'".')}v.scanLine(w)})},parseTemplateText:function(){var f=this.templateText,v=this.regex,g=v.exec(f),C=[],A;while(g){if(A=g.index,A!==0)C.push(f.substring(0,A)),f=f.slice(A);C.push(g[0]),f=f.slice(g[0].length),g=v.exec(f)}if(f)C.push(f);return C},_addOutput:function(f){if(this.truncate)f=f.replace(/^(?:\r\n|\r|\n)/,""),this.truncate=!1;if(!f)return f;f=f.replace(/\\/g,"\\\\"),f=f.replace(/\n/g,"\\n"),f=f.replace(/\r/g,"\\r"),f=f.replace(/"/g,"\\\""),this.source+=' ; __append("'+f+`")
|
|
45
|
+
`},scanLine:function(f){var v=this,g=this.opts.delimiter,C=this.opts.openDelimiter,A=this.opts.closeDelimiter,b=0;switch(b=f.split(`
|
|
46
|
+
`).length-1,f){case C+g:case C+g+"_":this.mode=$.modes.EVAL;break;case C+g+"=":this.mode=$.modes.ESCAPED;break;case C+g+"-":this.mode=$.modes.RAW;break;case C+g+"#":this.mode=$.modes.COMMENT;break;case C+g+g:this.mode=$.modes.LITERAL,this.source+=' ; __append("'+f.replace(C+g+g,C+g)+`")
|
|
47
|
+
`;break;case g+g+A:this.mode=$.modes.LITERAL,this.source+=' ; __append("'+f.replace(g+g+A,g+A)+`")
|
|
48
|
+
`;break;case g+A:case"-"+g+A:case"_"+g+A:if(this.mode==$.modes.LITERAL)this._addOutput(f);this.mode=null,this.truncate=f.indexOf("-")===0||f.indexOf("_")===0;break;default:if(this.mode){switch(this.mode){case $.modes.EVAL:case $.modes.ESCAPED:case $.modes.RAW:if(f.lastIndexOf("//")>f.lastIndexOf(`
|
|
49
49
|
`))f+=`
|
|
50
|
-
`}switch(this.mode){case
|
|
51
|
-
`;break;case
|
|
52
|
-
`;break;case
|
|
53
|
-
`;break;case
|
|
54
|
-
`}}
|
|
50
|
+
`}switch(this.mode){case $.modes.EVAL:this.source+=" ; "+f+`
|
|
51
|
+
`;break;case $.modes.ESCAPED:this.source+=" ; __append(escapeFn("+K1(f)+`))
|
|
52
|
+
`;break;case $.modes.RAW:this.source+=" ; __append("+K1(f)+`)
|
|
53
|
+
`;break;case $.modes.COMMENT:break;case $.modes.LITERAL:this._addOutput(f);break}}else this._addOutput(f)}if(v.opts.compileDebug&&b)this.currentLine+=b,this.source+=" ; __line = "+this.currentLine+`
|
|
54
|
+
`}};$1.escapeXML=Z.escapeXML;$1.__express=$1.renderFile;$1.VERSION=d1;$1.name=i1;if(typeof window!="undefined")window.ejs=$1});function _(f){switch(f.split(".").pop()?.toLowerCase()){case"js":return"application/javascript";case"css":return"text/css";case"html":return"text/html";case"json":return"application/json";case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"svg":return"image/svg+xml";case"gif":return"image/gif";case"woff":return"font/woff";case"woff2":return"font/woff2";default:return"application/octet-stream"}}var x=null;async function j0(){if(!x){let f=await Promise.resolve().then(() => H1(G1(),1));x=f.default||f}return x}class z0{req;server;path;routePattern;env;executionCtx;headers=new Headers;parsedQuery=null;parsedParams=null;parsedCookies=null;parsedBody=null;contextData={};urlObject=null;constructor(f,v,g,C,A,b){this.req=f,this.server=v,this.path=g,this.routePattern=C,this.executionCtx=b,this.env=A}setHeader(f,v){return this.headers.set(f,v),this}removeHeader(f){return this.headers.delete(f),this}set(f,v){return this.contextData[f]=v,this}get(f){return this.contextData[f]}get ip(){if(this.server)return this.server.requestIP(this.req)?.address??null;return this.req.headers.get("CF-Connecting-IP")||null}get url(){if(!this.urlObject)this.urlObject=new URL(this.req.url);return this.urlObject}get query(){if(!this.parsedQuery)this.parsedQuery=this.url.search?Object.fromEntries(this.url.searchParams):{};return this.parsedQuery}get params(){if(!this.parsedParams&&this.routePattern)try{this.parsedParams=Y0(this.routePattern,this.path)}catch(f){let v=f instanceof Error?f.message:String(f);throw new Error(`Failed to extract route parameters: ${v}`)}return this.parsedParams??{}}get body(){if(this.req.method==="GET")return Promise.resolve({});if(!this.parsedBody)this.parsedBody=(async()=>{try{let f=await Z0(this.req);if(f.error)throw new Error(f.error);return Object.keys(f).length===0?null:f}catch(f){throw new Error("Invalid request body format")}})();return this.parsedBody}text(f,v=200){return new Response(f,{status:v,headers:this.headers})}send(f,v=200){let g;if(f instanceof Uint8Array)g="Uint8Array";else if(f instanceof ArrayBuffer)g="ArrayBuffer";else g=typeof f;let C=g==="object"&&f!==null?JSON.stringify(f):f;return new Response(C,{status:v,headers:this.headers})}json(f,v=200){return Response.json(f,{status:v,headers:this.headers})}file(f,v,g=200){let C=Bun.file(f);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",v??_(f));return new Response(C,{status:g,headers:this.headers})}async ejs(f,v={},g=200){let C=await j0();try{let A=await Bun.file(f).text(),b=C.render(A,v),w=new Headers({"Content-Type":"text/html; charset=utf-8"});return new Response(b,{status:g,headers:w})}catch(A){return console.error("EJS Rendering Error:",A),new Response("Error rendering template",{status:500})}}redirect(f,v=302){return this.headers.set("Location",f),new Response(null,{status:v,headers:this.headers})}setCookie(f,v,g={}){let C=`${encodeURIComponent(f)}=${encodeURIComponent(v)}`;if(g.maxAge)C+=`; Max-Age=${g.maxAge}`;if(g.expires)C+=`; Expires=${g.expires.toUTCString()}`;if(g.path)C+=`; Path=${g.path}`;if(g.domain)C+=`; Domain=${g.domain}`;if(g.secure)C+="; Secure";if(g.httpOnly)C+="; HttpOnly";if(g.sameSite)C+=`; SameSite=${g.sameSite}`;return this.headers.append("Set-Cookie",C),this}get cookies(){if(!this.parsedCookies){let f=this.req.headers.get("cookie");this.parsedCookies=f?K0(f):{}}return this.parsedCookies}stream(f){let v=new Headers(this.headers),g=new ReadableStream({async start(C){await f(C),C.close()}});return new Response(g,{headers:v})}yieldStream(f){return new Response}}function K0(f){return Object.fromEntries(f.split(";").map((v)=>{let[g,...C]=v.trim().split("=");return[g,decodeURIComponent(C.join("="))]}))}function Y0(f,v){let g={},C=f.split("/"),[A]=v.split("?"),b=A.split("/");if(C.length!==b.length)return null;for(let w=0;w<C.length;w++){let j=C[w];if(j.charCodeAt(0)===58)g[j.slice(1)]=b[w]}return g}async function Z0(f){let v=f.headers.get("Content-Type")||"";if(!v)return{};if(f.headers.get("Content-Length")==="0"||!f.body)return{};if(v.startsWith("application/json"))return await f.json();if(v.startsWith("application/x-www-form-urlencoded")){let C=await f.text();return Object.fromEntries(new URLSearchParams(C))}if(v.startsWith("multipart/form-data")){let C=await f.formData(),A={};for(let[b,w]of C.entries())A[b]=w;return A}return{error:"Unknown request body type"}}export{Y0 as extractDynamicParams,z0 as Context};
|
package/dist/handleRequest.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Of=Object.create;var{getPrototypeOf:Lf,defineProperty:M,getOwnPropertyNames:i,getOwnPropertyDescriptor:Sf}=Object,u=Object.prototype.hasOwnProperty;var bf=(f,w,g)=>{g=f!=null?Of(Lf(f)):{};let A=w||!f||!f.__esModule?M(g,"default",{value:f,enumerable:!0}):g;for(let $ of i(f))if(!u.call(A,$))M(A,$,{get:()=>f[$],enumerable:!0});return A},r=new WeakMap,Ef=(f)=>{var w=r.get(f),g;if(w)return w;if(w=M({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")i(f).map((A)=>!u.call(w,A)&&M(w,A,{get:()=>f[A],enumerable:!(g=Sf(f,A))||g.enumerable}));return r.set(f,w),w},L=(f,w)=>()=>(w||f((w={exports:{}}).exports,w),w.exports);var qf=(f,w)=>{for(var g in w)M(f,g,{get:w[g],enumerable:!0,configurable:!0,set:(A)=>w[g]=()=>A})};var Tf=(f,w)=>()=>(f&&(w=f(f=0)),w);var cf=((f)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(f,{get:(w,g)=>(typeof require!=="undefined"?require:w)[g]}):f)(function(f){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+f+'" is not supported')});var wf={};qf(wf,{sep:()=>e,resolve:()=>H,relative:()=>d,posix:()=>gf,parse:()=>t,normalize:()=>S,join:()=>m,isAbsolute:()=>h,format:()=>p,extname:()=>a,dirname:()=>o,delimiter:()=>ff,default:()=>_f,basename:()=>s,_makeLong:()=>l});function F(f){if(typeof f!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function n(f,w){var g="",A=0,$=-1,z=0,C;for(var J=0;J<=f.length;++J){if(J<f.length)C=f.charCodeAt(J);else if(C===47)break;else C=47;if(C===47){if($===J-1||z===1);else if($!==J-1&&z===2){if(g.length<2||A!==2||g.charCodeAt(g.length-1)!==46||g.charCodeAt(g.length-2)!==46){if(g.length>2){var Z=g.lastIndexOf("/");if(Z!==g.length-1){if(Z===-1)g="",A=0;else g=g.slice(0,Z),A=g.length-1-g.lastIndexOf("/");$=J,z=0;continue}}else if(g.length===2||g.length===1){g="",A=0,$=J,z=0;continue}}if(w){if(g.length>0)g+="/..";else g="..";A=2}}else{if(g.length>0)g+="/"+f.slice($+1,J);else g=f.slice($+1,J);A=J-$-1}$=J,z=0}else if(C===46&&z!==-1)++z;else z=-1}return g}function Pf(f,w){var g=w.dir||w.root,A=w.base||(w.name||"")+(w.ext||"");if(!g)return A;if(g===w.root)return g+A;return g+f+A}function H(){var f="",w=!1,g;for(var A=arguments.length-1;A>=-1&&!w;A--){var $;if(A>=0)$=arguments[A];else{if(g===void 0)g=process.cwd();$=g}if(F($),$.length===0)continue;f=$+"/"+f,w=$.charCodeAt(0)===47}if(f=n(f,!w),w)if(f.length>0)return"/"+f;else return"/";else if(f.length>0)return f;else return"."}function S(f){if(F(f),f.length===0)return".";var w=f.charCodeAt(0)===47,g=f.charCodeAt(f.length-1)===47;if(f=n(f,!w),f.length===0&&!w)f=".";if(f.length>0&&g)f+="/";if(w)return"/"+f;return f}function h(f){return F(f),f.length>0&&f.charCodeAt(0)===47}function m(){if(arguments.length===0)return".";var f;for(var w=0;w<arguments.length;++w){var g=arguments[w];if(F(g),g.length>0)if(f===void 0)f=g;else f+="/"+g}if(f===void 0)return".";return S(f)}function d(f,w){if(F(f),F(w),f===w)return"";if(f=H(f),w=H(w),f===w)return"";var g=1;for(;g<f.length;++g)if(f.charCodeAt(g)!==47)break;var A=f.length,$=A-g,z=1;for(;z<w.length;++z)if(w.charCodeAt(z)!==47)break;var C=w.length,J=C-z,Z=$<J?$:J,j=-1,Y=0;for(;Y<=Z;++Y){if(Y===Z){if(J>Z){if(w.charCodeAt(z+Y)===47)return w.slice(z+Y+1);else if(Y===0)return w.slice(z+Y)}else if($>Z){if(f.charCodeAt(g+Y)===47)j=Y;else if(Y===0)j=0}break}var X=f.charCodeAt(g+Y),W=w.charCodeAt(z+Y);if(X!==W)break;else if(X===47)j=Y}var G="";for(Y=g+j+1;Y<=A;++Y)if(Y===A||f.charCodeAt(Y)===47)if(G.length===0)G+="..";else G+="/..";if(G.length>0)return G+w.slice(z+j);else{if(z+=j,w.charCodeAt(z)===47)++z;return w.slice(z)}}function l(f){return f}function o(f){if(F(f),f.length===0)return".";var w=f.charCodeAt(0),g=w===47,A=-1,$=!0;for(var z=f.length-1;z>=1;--z)if(w=f.charCodeAt(z),w===47){if(!$){A=z;break}}else $=!1;if(A===-1)return g?"/":".";if(g&&A===1)return"//";return f.slice(0,A)}function s(f,w){if(w!==void 0&&typeof w!=="string")throw new TypeError('"ext" argument must be a string');F(f);var g=0,A=-1,$=!0,z;if(w!==void 0&&w.length>0&&w.length<=f.length){if(w.length===f.length&&w===f)return"";var C=w.length-1,J=-1;for(z=f.length-1;z>=0;--z){var Z=f.charCodeAt(z);if(Z===47){if(!$){g=z+1;break}}else{if(J===-1)$=!1,J=z+1;if(C>=0)if(Z===w.charCodeAt(C)){if(--C===-1)A=z}else C=-1,A=J}}if(g===A)A=J;else if(A===-1)A=f.length;return f.slice(g,A)}else{for(z=f.length-1;z>=0;--z)if(f.charCodeAt(z)===47){if(!$){g=z+1;break}}else if(A===-1)$=!1,A=z+1;if(A===-1)return"";return f.slice(g,A)}}function a(f){F(f);var w=-1,g=0,A=-1,$=!0,z=0;for(var C=f.length-1;C>=0;--C){var J=f.charCodeAt(C);if(J===47){if(!$){g=C+1;break}continue}if(A===-1)$=!1,A=C+1;if(J===46){if(w===-1)w=C;else if(z!==1)z=1}else if(w!==-1)z=-1}if(w===-1||A===-1||z===0||z===1&&w===A-1&&w===g+1)return"";return f.slice(w,A)}function p(f){if(f===null||typeof f!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof f);return Pf("/",f)}function t(f){F(f);var w={root:"",dir:"",base:"",ext:"",name:""};if(f.length===0)return w;var g=f.charCodeAt(0),A=g===47,$;if(A)w.root="/",$=1;else $=0;var z=-1,C=0,J=-1,Z=!0,j=f.length-1,Y=0;for(;j>=$;--j){if(g=f.charCodeAt(j),g===47){if(!Z){C=j+1;break}continue}if(J===-1)Z=!1,J=j+1;if(g===46){if(z===-1)z=j;else if(Y!==1)Y=1}else if(z!==-1)Y=-1}if(z===-1||J===-1||Y===0||Y===1&&z===J-1&&z===C+1){if(J!==-1)if(C===0&&A)w.base=w.name=f.slice(1,J);else w.base=w.name=f.slice(C,J)}else{if(C===0&&A)w.name=f.slice(1,z),w.base=f.slice(1,J);else w.name=f.slice(C,z),w.base=f.slice(C,J);w.ext=f.slice(z,J)}if(C>0)w.dir=f.slice(0,C-1);else if(A)w.dir="/";return w}var e="/",ff=":",gf,_f;var Af=Tf(()=>{gf=((f)=>(f.posix=f,f))({resolve:H,normalize:S,isAbsolute:h,join:m,relative:d,_makeLong:l,dirname:o,basename:s,extname:a,format:p,parse:t,sep:e,delimiter:ff,win32:null,posix:null}),_f=gf});var Cf=L((nf)=>{var yf=/[|\\{}()[\]^$+*?.]/g,kf=Object.prototype.hasOwnProperty,E=function(f,w){return kf.apply(f,[w])};nf.escapeRegExpChars=function(f){if(!f)return"";return String(f).replace(yf,"\\$&")};var If={"&":"&","<":"<",">":">",'"':""","'":"'"},xf=/[&<>'"]/g;function rf(f){return If[f]||f}var uf=`var _ENCODE_HTML_RULES = {
|
|
2
2
|
"&": "&"
|
|
3
3
|
, "<": "<"
|
|
4
4
|
, ">": ">"
|
|
@@ -9,46 +9,46 @@ var bf=Object.create;var{getPrototypeOf:Tf,defineProperty:M,getOwnPropertyNames:
|
|
|
9
9
|
function encode_char(c) {
|
|
10
10
|
return _ENCODE_HTML_RULES[c] || c;
|
|
11
11
|
};
|
|
12
|
-
`;
|
|
13
|
-
`+
|
|
14
|
-
`),
|
|
15
|
-
`);throw f.path=
|
|
16
|
-
`+
|
|
12
|
+
`;nf.escapeXML=function(f){return f==null?"":String(f).replace(xf,rf)};function $f(){return Function.prototype.toString.call(this)+`;
|
|
13
|
+
`+uf}try{if(typeof Object.defineProperty==="function")Object.defineProperty(nf.escapeXML,"toString",{value:$f});else nf.escapeXML.toString=$f}catch(f){console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)")}nf.shallowCopy=function(f,w){if(w=w||{},f!==null&&f!==void 0)for(var g in w){if(!E(w,g))continue;if(g==="__proto__"||g==="constructor")continue;f[g]=w[g]}return f};nf.shallowCopyFromList=function(f,w,g){if(g=g||[],w=w||{},f!==null&&f!==void 0)for(var A=0;A<g.length;A++){var $=g[A];if(typeof w[$]!="undefined"){if(!E(w,$))continue;if($==="__proto__"||$==="constructor")continue;f[$]=w[$]}}return f};nf.cache={_data:{},set:function(f,w){this._data[f]=w},get:function(f){return this._data[f]},remove:function(f){delete this._data[f]},reset:function(){this._data={}}};nf.hyphenToCamel=function(f){return f.replace(/-[a-z]/g,function(w){return w[1].toUpperCase()})};nf.createNullProtoObjWherePossible=function(){if(typeof Object.create=="function")return function(){return Object.create(null)};if(!({__proto__:null}instanceof Object))return function(){return{__proto__:null}};return function(){return{}}}();nf.hasOwnOnlyObject=function(f){var w=nf.createNullProtoObjWherePossible();for(var g in f)if(E(f,g))w[g]=f[g];return w}});var Jf=L((O1,af)=>{af.exports={name:"ejs",description:"Embedded JavaScript templates",keywords:["template","engine","ejs"],version:"3.1.10",author:"Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",license:"Apache-2.0",bin:{ejs:"./bin/cli.js"},main:"./lib/ejs.js",jsdelivr:"ejs.min.js",unpkg:"ejs.min.js",repository:{type:"git",url:"git://github.com/mde/ejs.git"},bugs:"https://github.com/mde/ejs/issues",homepage:"https://github.com/mde/ejs",dependencies:{jake:"^10.8.5"},devDependencies:{browserify:"^16.5.1",eslint:"^6.8.0","git-directory-deploy":"^1.5.1",jsdoc:"^4.0.2","lru-cache":"^4.0.1",mocha:"^10.2.0","uglify-js":"^3.3.16"},engines:{node:">=0.10.0"},scripts:{test:"npx jake test"}}});var Nf=L((Ff)=>{var c=(()=>({})),R=(Af(),Ef(wf)),V=Cf(),Yf=!1,pf=Jf().version,tf="<",ef=">",f1="%",Wf="locals",g1="ejs",w1="(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)",Xf=["delimiter","scope","context","debug","compileDebug","client","_with","rmWhitespace","strict","filename","async"],A1=Xf.concat("cache"),Zf=/^\uFEFF/,q=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/;Ff.cache=V.cache;Ff.fileLoader=c.readFileSync;Ff.localsName=Wf;Ff.promiseImpl=new Function("return this;")().Promise;Ff.resolveInclude=function(f,w,g){var{dirname:A,extname:$,resolve:z}=R,C=z(g?w:A(w),f),J=$(f);if(!J)C+=".ejs";return C};function jf(f,w){var g;if(w.some(function(A){return g=Ff.resolveInclude(f,A,!0),c.existsSync(g)}))return g}function $1(f,w){var g,A,$=w.views,z=/^[A-Za-z]+:\\|^\//.exec(f);if(z&&z.length)if(f=f.replace(/^\/*/,""),Array.isArray(w.root))g=jf(f,w.root);else g=Ff.resolveInclude(f,w.root||"/",!0);else{if(w.filename){if(A=Ff.resolveInclude(f,w.filename),c.existsSync(A))g=A}if(!g&&Array.isArray($))g=jf(f,$);if(!g&&typeof w.includer!=="function")throw new Error('Could not find the include file "'+w.escapeFunction(f)+'"')}return g}function N(f,w){var g,A=f.filename,$=arguments.length>1;if(f.cache){if(!A)throw new Error("cache option requires a filename");if(g=Ff.cache.get(A),g)return g;if(!$)w=Vf(A).toString().replace(Zf,"")}else if(!$){if(!A)throw new Error("Internal EJS error: no file name or template provided");w=Vf(A).toString().replace(Zf,"")}if(g=Ff.compile(w,f),f.cache)Ff.cache.set(A,g);return g}function z1(f,w,g){var A;if(!g)if(typeof Ff.promiseImpl=="function")return new Ff.promiseImpl(function($,z){try{A=N(f)(w),$(A)}catch(C){z(C)}});else throw new Error("Please provide a callback function");else{try{A=N(f)(w)}catch($){return g($)}g(null,A)}}function Vf(f){return Ff.fileLoader(f)}function C1(f,w){var g=V.shallowCopy(V.createNullProtoObjWherePossible(),w);if(g.filename=$1(f,g),typeof w.includer==="function"){var A=w.includer(f,g.filename);if(A){if(A.filename)g.filename=A.filename;if(A.template)return N(g,A.template)}}return N(g)}function Qf(f,w,g,A,$){var z=w.split(`
|
|
14
|
+
`),C=Math.max(A-3,0),J=Math.min(z.length,A+3),Z=$(g),j=z.slice(C,J).map(function(Y,X){var W=X+C+1;return(W==A?" >> ":" ")+W+"| "+Y}).join(`
|
|
15
|
+
`);throw f.path=Z,f.message=(Z||"ejs")+":"+A+`
|
|
16
|
+
`+j+`
|
|
17
17
|
|
|
18
|
-
`+f.message,f}function
|
|
18
|
+
`+f.message,f}function Bf(f){return f.replace(/;(\s*$)/,"$1")}Ff.compile=function f(w,g){var A;if(g&&g.scope){if(!Yf)console.warn("`scope` option is deprecated and will be removed in EJS 3"),Yf=!0;if(!g.context)g.context=g.scope;delete g.scope}return A=new Q(w,g),A.compile()};Ff.render=function(f,w,g){var A=w||V.createNullProtoObjWherePossible(),$=g||V.createNullProtoObjWherePossible();if(arguments.length==2)V.shallowCopyFromList($,A,Xf);return N($,f)(A)};Ff.renderFile=function(){var f=Array.prototype.slice.call(arguments),w=f.shift(),g,A={filename:w},$,z;if(typeof arguments[arguments.length-1]=="function")g=f.pop();if(f.length){if($=f.shift(),f.length)V.shallowCopy(A,f.pop());else{if($.settings){if($.settings.views)A.views=$.settings.views;if($.settings["view cache"])A.cache=!0;if(z=$.settings["view options"],z)V.shallowCopy(A,z)}V.shallowCopyFromList(A,$,A1)}A.filename=w}else $=V.createNullProtoObjWherePossible();return z1(A,$,g)};Ff.Template=Q;Ff.clearCache=function(){Ff.cache.reset()};function Q(f,w){var g=V.hasOwnOnlyObject(w),A=V.createNullProtoObjWherePossible();if(this.templateText=f,this.mode=null,this.truncate=!1,this.currentLine=1,this.source="",A.client=g.client||!1,A.escapeFunction=g.escape||g.escapeFunction||V.escapeXML,A.compileDebug=g.compileDebug!==!1,A.debug=!!g.debug,A.filename=g.filename,A.openDelimiter=g.openDelimiter||Ff.openDelimiter||tf,A.closeDelimiter=g.closeDelimiter||Ff.closeDelimiter||ef,A.delimiter=g.delimiter||Ff.delimiter||f1,A.strict=g.strict||!1,A.context=g.context,A.cache=g.cache||!1,A.rmWhitespace=g.rmWhitespace,A.root=g.root,A.includer=g.includer,A.outputFunctionName=g.outputFunctionName,A.localsName=g.localsName||Ff.localsName||Wf,A.views=g.views,A.async=g.async,A.destructuredLocals=g.destructuredLocals,A.legacyInclude=typeof g.legacyInclude!="undefined"?!!g.legacyInclude:!0,A.strict)A._with=!1;else A._with=typeof g._with!="undefined"?g._with:!0;this.opts=A,this.regex=this.createRegex()}Q.modes={EVAL:"eval",ESCAPED:"escaped",RAW:"raw",COMMENT:"comment",LITERAL:"literal"};Q.prototype={createRegex:function(){var f=w1,w=V.escapeRegExpChars(this.opts.delimiter),g=V.escapeRegExpChars(this.opts.openDelimiter),A=V.escapeRegExpChars(this.opts.closeDelimiter);return f=f.replace(/%/g,w).replace(/</g,g).replace(/>/g,A),new RegExp(f)},compile:function(){var f,w,g=this.opts,A="",$="",z=g.escapeFunction,C,J=g.filename?JSON.stringify(g.filename):"undefined";if(!this.source){if(this.generateSource(),A+=` var __output = "";
|
|
19
19
|
function __append(s) { if (s !== undefined && s !== null) __output += s }
|
|
20
|
-
`,g.outputFunctionName){if(!
|
|
21
|
-
`}if(g.localsName&&!
|
|
22
|
-
`;for(var
|
|
23
|
-
`;
|
|
20
|
+
`,g.outputFunctionName){if(!q.test(g.outputFunctionName))throw new Error("outputFunctionName is not a valid JS identifier.");A+=" var "+g.outputFunctionName+` = __append;
|
|
21
|
+
`}if(g.localsName&&!q.test(g.localsName))throw new Error("localsName is not a valid JS identifier.");if(g.destructuredLocals&&g.destructuredLocals.length){var Z=" var __locals = ("+g.localsName+` || {}),
|
|
22
|
+
`;for(var j=0;j<g.destructuredLocals.length;j++){var Y=g.destructuredLocals[j];if(!q.test(Y))throw new Error("destructuredLocals["+j+"] is not a valid JS identifier.");if(j>0)Z+=`,
|
|
23
|
+
`;Z+=Y+" = __locals."+Y}A+=Z+`;
|
|
24
24
|
`}if(g._with!==!1)A+=" with ("+g.localsName+` || {}) {
|
|
25
25
|
`,$+=` }
|
|
26
26
|
`;$+=` return __output;
|
|
27
27
|
`,this.source=A+this.source+$}if(g.compileDebug)f=`var __line = 1
|
|
28
28
|
, __lines = `+JSON.stringify(this.templateText)+`
|
|
29
|
-
, __filename = `+
|
|
29
|
+
, __filename = `+J+`;
|
|
30
30
|
try {
|
|
31
31
|
`+this.source+`} catch (e) {
|
|
32
32
|
rethrow(e, __lines, __filename, __line, escapeFn);
|
|
33
33
|
}
|
|
34
34
|
`;else f=this.source;if(g.client){if(f="escapeFn = escapeFn || "+z.toString()+`;
|
|
35
|
-
`+f,g.compileDebug)f="rethrow = rethrow || "+
|
|
35
|
+
`+f,g.compileDebug)f="rethrow = rethrow || "+Qf.toString()+`;
|
|
36
36
|
`+f}if(g.strict)f=`"use strict";
|
|
37
37
|
`+f;if(g.debug)console.log(f);if(g.compileDebug&&g.filename)f=f+`
|
|
38
|
-
//# sourceURL=`+
|
|
39
|
-
`;try{if(g.async)try{
|
|
38
|
+
//# sourceURL=`+J+`
|
|
39
|
+
`;try{if(g.async)try{C=new Function("return (async function(){}).constructor;")()}catch(B){if(B instanceof SyntaxError)throw new Error("This environment does not support async/await");else throw B}else C=Function;w=new C(g.localsName+", escapeFn, include, rethrow",f)}catch(B){if(B instanceof SyntaxError){if(g.filename)B.message+=" in "+g.filename;if(B.message+=` while compiling ejs
|
|
40
40
|
|
|
41
41
|
`,B.message+=`If the above error is not helpful, you may want to try EJS-Lint:
|
|
42
42
|
`,B.message+="https://github.com/RyanZim/EJS-Lint",!g.async)B.message+=`
|
|
43
|
-
`,B.message+="Or, if you meant to create an async function, pass `async: true` as an option."}throw B}var X=g.client?w:function B(
|
|
44
|
-
`).replace(/^\s+|\s+$/gm,"");this.templateText=this.templateText.replace(/[ \t]*<%_/gm,"<%_").replace(/_%>[ \t]*/gm,"_%>");var w=this,g=this.parseTemplateText(),A=this.opts.delimiter,$=this.opts.openDelimiter,z=this.opts.closeDelimiter;if(g&&g.length)g.forEach(function(
|
|
43
|
+
`,B.message+="Or, if you meant to create an async function, pass `async: true` as an option."}throw B}var X=g.client?w:function B(I){var Kf=function(Df,x){var O=V.shallowCopy(V.createNullProtoObjWherePossible(),I);if(x)O=V.shallowCopy(O,x);return C1(Df,g)(O)};return w.apply(g.context,[I||V.createNullProtoObjWherePossible(),z,Kf,Qf])};if(g.filename&&typeof Object.defineProperty==="function"){var W=g.filename,G=R.basename(W,R.extname(W));try{Object.defineProperty(X,"name",{value:G,writable:!1,enumerable:!1,configurable:!0})}catch(B){}}return X},generateSource:function(){var f=this.opts;if(f.rmWhitespace)this.templateText=this.templateText.replace(/[\r\n]+/g,`
|
|
44
|
+
`).replace(/^\s+|\s+$/gm,"");this.templateText=this.templateText.replace(/[ \t]*<%_/gm,"<%_").replace(/_%>[ \t]*/gm,"_%>");var w=this,g=this.parseTemplateText(),A=this.opts.delimiter,$=this.opts.openDelimiter,z=this.opts.closeDelimiter;if(g&&g.length)g.forEach(function(C,J){var Z;if(C.indexOf($+A)===0&&C.indexOf($+A+A)!==0){if(Z=g[J+2],!(Z==A+z||Z=="-"+A+z||Z=="_"+A+z))throw new Error('Could not find matching close tag for "'+C+'".')}w.scanLine(C)})},parseTemplateText:function(){var f=this.templateText,w=this.regex,g=w.exec(f),A=[],$;while(g){if($=g.index,$!==0)A.push(f.substring(0,$)),f=f.slice($);A.push(g[0]),f=f.slice(g[0].length),g=w.exec(f)}if(f)A.push(f);return A},_addOutput:function(f){if(this.truncate)f=f.replace(/^(?:\r\n|\r|\n)/,""),this.truncate=!1;if(!f)return f;f=f.replace(/\\/g,"\\\\"),f=f.replace(/\n/g,"\\n"),f=f.replace(/\r/g,"\\r"),f=f.replace(/"/g,"\\\""),this.source+=' ; __append("'+f+`")
|
|
45
45
|
`},scanLine:function(f){var w=this,g=this.opts.delimiter,A=this.opts.openDelimiter,$=this.opts.closeDelimiter,z=0;switch(z=f.split(`
|
|
46
46
|
`).length-1,f){case A+g:case A+g+"_":this.mode=Q.modes.EVAL;break;case A+g+"=":this.mode=Q.modes.ESCAPED;break;case A+g+"-":this.mode=Q.modes.RAW;break;case A+g+"#":this.mode=Q.modes.COMMENT;break;case A+g+g:this.mode=Q.modes.LITERAL,this.source+=' ; __append("'+f.replace(A+g+g,A+g)+`")
|
|
47
47
|
`;break;case g+g+$:this.mode=Q.modes.LITERAL,this.source+=' ; __append("'+f.replace(g+g+$,g+$)+`")
|
|
48
48
|
`;break;case g+$:case"-"+g+$:case"_"+g+$:if(this.mode==Q.modes.LITERAL)this._addOutput(f);this.mode=null,this.truncate=f.indexOf("-")===0||f.indexOf("_")===0;break;default:if(this.mode){switch(this.mode){case Q.modes.EVAL:case Q.modes.ESCAPED:case Q.modes.RAW:if(f.lastIndexOf("//")>f.lastIndexOf(`
|
|
49
49
|
`))f+=`
|
|
50
50
|
`}switch(this.mode){case Q.modes.EVAL:this.source+=" ; "+f+`
|
|
51
|
-
`;break;case Q.modes.ESCAPED:this.source+=" ; __append(escapeFn("+
|
|
52
|
-
`;break;case Q.modes.RAW:this.source+=" ; __append("+
|
|
51
|
+
`;break;case Q.modes.ESCAPED:this.source+=" ; __append(escapeFn("+Bf(f)+`))
|
|
52
|
+
`;break;case Q.modes.RAW:this.source+=" ; __append("+Bf(f)+`)
|
|
53
53
|
`;break;case Q.modes.COMMENT:break;case Q.modes.LITERAL:this._addOutput(f);break}}else this._addOutput(f)}if(w.opts.compileDebug&&z)this.currentLine+=z,this.source+=" ; __line = "+this.currentLine+`
|
|
54
|
-
`}};
|
|
54
|
+
`}};Ff.escapeXML=V.escapeXML;Ff.__express=Ff.renderFile;Ff.VERSION=pf;Ff.name=g1;if(typeof window!="undefined")window.ejs=Ff});function U(f){switch(f.split(".").pop()?.toLowerCase()){case"js":return"application/javascript";case"css":return"text/css";case"html":return"text/html";case"json":return"application/json";case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"svg":return"image/svg+xml";case"gif":return"image/gif";case"woff":return"font/woff";case"woff2":return"font/woff2";default:return"application/octet-stream"}}var P=null;async function X1(){if(!P){let f=await Promise.resolve().then(() => bf(Nf(),1));P=f.default||f}return P}class _{req;server;path;routePattern;env;executionCtx;headers=new Headers;parsedQuery=null;parsedParams=null;parsedCookies=null;parsedBody=null;contextData={};urlObject=null;constructor(f,w,g,A,$,z){this.req=f,this.server=w,this.path=g,this.routePattern=A,this.executionCtx=z,this.env=$}setHeader(f,w){return this.headers.set(f,w),this}removeHeader(f){return this.headers.delete(f),this}set(f,w){return this.contextData[f]=w,this}get(f){return this.contextData[f]}get ip(){if(this.server)return this.server.requestIP(this.req)?.address??null;return this.req.headers.get("CF-Connecting-IP")||null}get url(){if(!this.urlObject)this.urlObject=new URL(this.req.url);return this.urlObject}get query(){if(!this.parsedQuery)this.parsedQuery=this.url.search?Object.fromEntries(this.url.searchParams):{};return this.parsedQuery}get params(){if(!this.parsedParams&&this.routePattern)try{this.parsedParams=G1(this.routePattern,this.path)}catch(f){let w=f instanceof Error?f.message:String(f);throw new Error(`Failed to extract route parameters: ${w}`)}return this.parsedParams??{}}get body(){if(this.req.method==="GET")return Promise.resolve({});if(!this.parsedBody)this.parsedBody=(async()=>{try{let f=await M1(this.req);if(f.error)throw new Error(f.error);return Object.keys(f).length===0?null:f}catch(f){throw new Error("Invalid request body format")}})();return this.parsedBody}text(f,w=200){return new Response(f,{status:w,headers:this.headers})}send(f,w=200){let g;if(f instanceof Uint8Array)g="Uint8Array";else if(f instanceof ArrayBuffer)g="ArrayBuffer";else g=typeof f;let A=g==="object"&&f!==null?JSON.stringify(f):f;return new Response(A,{status:w,headers:this.headers})}json(f,w=200){return Response.json(f,{status:w,headers:this.headers})}file(f,w,g=200){let A=Bun.file(f);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",w??U(f));return new Response(A,{status:g,headers:this.headers})}async ejs(f,w={},g=200){let A=await X1();try{let $=await Bun.file(f).text(),z=A.render($,w),C=new Headers({"Content-Type":"text/html; charset=utf-8"});return new Response(z,{status:g,headers:C})}catch($){return console.error("EJS Rendering Error:",$),new Response("Error rendering template",{status:500})}}redirect(f,w=302){return this.headers.set("Location",f),new Response(null,{status:w,headers:this.headers})}setCookie(f,w,g={}){let A=`${encodeURIComponent(f)}=${encodeURIComponent(w)}`;if(g.maxAge)A+=`; Max-Age=${g.maxAge}`;if(g.expires)A+=`; Expires=${g.expires.toUTCString()}`;if(g.path)A+=`; Path=${g.path}`;if(g.domain)A+=`; Domain=${g.domain}`;if(g.secure)A+="; Secure";if(g.httpOnly)A+="; HttpOnly";if(g.sameSite)A+=`; SameSite=${g.sameSite}`;return this.headers.append("Set-Cookie",A),this}get cookies(){if(!this.parsedCookies){let f=this.req.headers.get("cookie");this.parsedCookies=f?F1(f):{}}return this.parsedCookies}stream(f){let w=new Headers(this.headers),g=new ReadableStream({async start(A){await f(A),A.close()}});return new Response(g,{headers:w})}yieldStream(f){return new Response}}function F1(f){return Object.fromEntries(f.split(";").map((w)=>{let[g,...A]=w.trim().split("=");return[g,decodeURIComponent(A.join("="))]}))}function G1(f,w){let g={},A=f.split("/"),[$]=w.split("?"),z=$.split("/");if(A.length!==z.length)return null;for(let C=0;C<A.length;C++){let J=A[C];if(J.charCodeAt(0)===58)g[J.slice(1)]=z[C]}return g}async function M1(f){let w=f.headers.get("Content-Type")||"";if(!w)return{};if(f.headers.get("Content-Length")==="0"||!f.body)return{};if(w.startsWith("application/json"))return await f.json();if(w.startsWith("application/x-www-form-urlencoded")){let A=await f.text();return Object.fromEntries(new URLSearchParams(A))}if(w.startsWith("multipart/form-data")){let A=await f.formData(),$={};for(let[z,C]of A.entries())$[z]=C;return $}return{error:"Unknown request body type"}}var R1=(f,w)=>{try{return w(f)}catch{return f.replace(/(?:%[0-9A-Fa-f]{2})+/g,(g)=>{try{return w(g)}catch{return g}})}},y=(f)=>R1(f,decodeURI),c1=(f)=>{let w=f.indexOf("/",f.indexOf(":")+4),g=w;for(;g<f.length;g++){let A=f.charCodeAt(g);if(A===37){let $=f.indexOf("?",g),z=f.slice(w,$===-1?void 0:$);return y(z.includes("%25")?z.replace(/%25/g,"%2525"):z)}else if(A===63)break}return f.slice(w,g)};async function D(f,w,g){if(!w?.length)return;for(let A=0;A<w.length;A++){let $=w[A](...g),z=$ instanceof Promise?await $:$;if(z&&f!=="onRequest")return z}}async function Uf(f,w,g){let A=f.globalMiddlewares;if(A.length)for(let z of A){let C=await z(g);if(C)return C}let $=f.middlewares.get(w);if($&&$.length)for(let z of $){let C=await z(g);if(C)return C}return null}async function y1(f,w,g){for(let A of f){let $=await A(w,g);if($)return $}}async function Hf(f,w,g){let A=await N1(f,w,g),$=A instanceof Promise?await A:A;if($)return $}async function N1(f,w,g){if(w.endsWith("/"))w=w.slice(0,-1);if(!f.filters.has(w))if(f.filterFunction.length)for(let A of f.filterFunction){let $=await A(g);if($)return $}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function vf(f,w,g){if(f.staticPath){let $=!0;if(f.staticRequestPath)$=g.startsWith(f.staticRequestPath);if($){let z=await U1(f,g,w);if(z)return z;let C=f.trie.search("*",w.req.method);if(C?.handler)return await C.handler(w)}}let A=f.routeNotFoundFunc(w);return A instanceof Promise?await A:A||k(404,`404 Route not found for ${g}`)}function k(f,w){return new Response(JSON.stringify({error:w}),{status:f,headers:{"Content-Type":"application/json"}})}async function U1(f,w,g){if(!f.staticPath)return null;let A=`${f.staticPath}${w}`;if(await Bun.file(A).exists()){let z=U(A);return g.file(A,z,200)}return null}async function H1(f,w,g){let A,$=f.url.indexOf("/",f.url.indexOf(":")+4),z=$;for(;z<f.url.length;z++){let Y=f.url.charCodeAt(z);if(Y===37){let X=f.url.indexOf("?",z),W=f.url.slice($,X===-1?void 0:X);A=y(W.includes("%25")?W.replace(/%25/g,"%2525"):W);break}else if(Y===63)break}if(!A)A=f.url.slice($,z);let C=g.trie.search(A,f.method),J=new _(f,w,A,C?.path);if(g.hasOnReqHook)await D("onRequest",g.hooks.onRequest,[f,A,w]);if(g.hasMiddleware){let Y=await Uf(g,A,J);if(Y)return Y}if(g.hasFilterEnabled){let Y=await Hf(g,A,J);if(Y)return Y}if(!C)return await vf(g,J,A);if(g.hasPreHandlerHook){let Y=await D("preHandler",g.hooks.preHandler,[J]);if(Y)return Y}let Z=C.handler(J),j=Z instanceof Promise?await Z:Z;if(g.hasOnSendHook){let Y=await D("onSend",g.hooks.onSend,[J,j]);if(Y)return Y}if(j instanceof Response)return j;return k(500,"No response returned from handler.")}export{H1 as default};
|
package/dist/main.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { AdvancedLoggerOptions, LoggerOptions } from "./middlewares/logger/logge
|
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
6
|
type errorFormat = 'json' | 'text' | 'html' | string;
|
|
7
7
|
export default class Diesel {
|
|
8
|
+
#private;
|
|
8
9
|
private static instance;
|
|
9
10
|
fecth: any;
|
|
10
11
|
routes: Record<string, Function>;
|
|
@@ -25,7 +26,6 @@ export default class Diesel {
|
|
|
25
26
|
filterFunction: Function[];
|
|
26
27
|
private hasFilterEnabled;
|
|
27
28
|
private serverInstance;
|
|
28
|
-
staticPath: any;
|
|
29
29
|
staticFiles: any;
|
|
30
30
|
user_jwt_secret: string;
|
|
31
31
|
private baseApiUrl;
|
|
@@ -34,10 +34,12 @@ export default class Diesel {
|
|
|
34
34
|
routeNotFoundFunc: (c: ContextType) => void | Promise<void> | Promise<Response> | Response;
|
|
35
35
|
private prefixApiUrl;
|
|
36
36
|
compileConfig: CompileConfig | null;
|
|
37
|
-
private newPipelineArchitecture;
|
|
38
37
|
emitter: EventEmitter;
|
|
39
38
|
errorFormat: errorFormat;
|
|
40
|
-
|
|
39
|
+
platform: string;
|
|
40
|
+
staticPath: any;
|
|
41
|
+
staticRequestPath: string | undefined;
|
|
42
|
+
constructor({ jwtSecret, baseApiUrl, enableFileRouting, idleTimeOut, prefixApiUrl, onError, logger, pipelineArchitecture, errorFormat, platform }?: {
|
|
41
43
|
jwtSecret?: string;
|
|
42
44
|
baseApiUrl?: string;
|
|
43
45
|
enableFileRouting?: boolean;
|
|
@@ -47,6 +49,7 @@ export default class Diesel {
|
|
|
47
49
|
logger?: boolean;
|
|
48
50
|
pipelineArchitecture?: boolean;
|
|
49
51
|
errorFormat?: errorFormat;
|
|
52
|
+
platform?: string;
|
|
50
53
|
});
|
|
51
54
|
static router(prefix: string): Diesel;
|
|
52
55
|
/**
|
|
@@ -57,10 +60,10 @@ export default class Diesel {
|
|
|
57
60
|
*/
|
|
58
61
|
setupFilter(): FilterMethods;
|
|
59
62
|
redirect(incomingPath: string, redirectPath: string, statusCode?: 302): this;
|
|
60
|
-
serveStatic(filePath: string): this;
|
|
61
|
-
static(path: string): this;
|
|
63
|
+
serveStatic(filePath: string, requestPath?: string): this;
|
|
64
|
+
static(path: string, requestPath?: string): this;
|
|
62
65
|
staticHtml(args: Record<string, string>): this;
|
|
63
|
-
addHooks<T extends HookType>(typeOfHook: T, fnc:
|
|
66
|
+
addHooks<T extends HookType>(typeOfHook: T, fnc: Hooks[T][number]): this;
|
|
64
67
|
private compile;
|
|
65
68
|
private registerFileRoutes;
|
|
66
69
|
private loadRoutes;
|
|
@@ -69,8 +72,8 @@ export default class Diesel {
|
|
|
69
72
|
BunRoute(method: string, path: string, ...handlersOrResponse: any[]): this;
|
|
70
73
|
listen(port: any, ...args: listenArgsT[]): Server | void;
|
|
71
74
|
close(callback?: () => void): void;
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
cfFetch(request: Request, env: Record<string, any>, executionCtx: any): Promise<any>;
|
|
76
|
+
fetch(): ((request: Request, env?: Record<string, any>, executionContext?: any) => Promise<any>) | ((req: Request, server: Server) => any) | ((req: Request, server?: Server, env?: Record<string, any>, executionCtx?: any) => Promise<any>);
|
|
74
77
|
private handleError;
|
|
75
78
|
/**
|
|
76
79
|
* Registers a router instance for subrouting.
|