lambder 1.0.4 → 1.0.5
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 +6 -6
- package/package.json +1 -1
- package/src/index.ts +12 -6
package/dist/index.js
CHANGED
|
@@ -63,13 +63,13 @@ export default class Lambder {
|
|
|
63
63
|
addApi(condition, actionFn) {
|
|
64
64
|
let conditionFn = (renderContext) => false;
|
|
65
65
|
if (typeof condition === "string") {
|
|
66
|
-
conditionFn = (renderContext) => renderContext.url === this.apiPath && (renderContext.post?.api) === condition;
|
|
66
|
+
conditionFn = (renderContext) => renderContext.method === "POST" && renderContext.url === this.apiPath && (renderContext.post?.api) === condition;
|
|
67
67
|
}
|
|
68
68
|
else if (typeof condition === "function") {
|
|
69
|
-
conditionFn = async (renderContext) => renderContext.url === this.apiPath && (await condition(renderContext));
|
|
69
|
+
conditionFn = async (renderContext) => renderContext.method === "POST" && renderContext.url === this.apiPath && (await condition(renderContext));
|
|
70
70
|
}
|
|
71
71
|
else if (condition?.constructor == RegExp) {
|
|
72
|
-
conditionFn = (renderContext) => renderContext.url === this.apiPath && condition.test(renderContext.post?.api);
|
|
72
|
+
conditionFn = (renderContext) => renderContext.method === "POST" && renderContext.url === this.apiPath && condition.test(renderContext.post?.api);
|
|
73
73
|
}
|
|
74
74
|
else {
|
|
75
75
|
throw "Unsupported API Condition";
|
|
@@ -82,13 +82,13 @@ export default class Lambder {
|
|
|
82
82
|
addPath(condition, actionFn) {
|
|
83
83
|
let conditionFn = (renderContext) => false;
|
|
84
84
|
if (typeof condition === "string") {
|
|
85
|
-
conditionFn = (renderContext) => renderContext.url === condition;
|
|
85
|
+
conditionFn = (renderContext) => renderContext.method === "GET" && renderContext.url === condition;
|
|
86
86
|
}
|
|
87
87
|
else if (typeof condition === "function") {
|
|
88
|
-
conditionFn = async (renderContext) => (await condition(renderContext));
|
|
88
|
+
conditionFn = async (renderContext) => renderContext.method === "GET" && (await condition(renderContext));
|
|
89
89
|
}
|
|
90
90
|
else if (condition?.constructor == RegExp) {
|
|
91
|
-
conditionFn = (renderContext) => condition.test(renderContext.url);
|
|
91
|
+
conditionFn = (renderContext) => renderContext.method === "GET" && condition.test(renderContext.url);
|
|
92
92
|
}
|
|
93
93
|
else {
|
|
94
94
|
throw "Unsupported Path Condition";
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -109,11 +109,14 @@ export default class Lambder {
|
|
|
109
109
|
addApi(condition: string|ConditionFunction|RegExp, actionFn: ActionFunction):void{
|
|
110
110
|
let conditionFn: ConditionFunction = (renderContext:RenderContext) => false;
|
|
111
111
|
if(typeof condition === "string"){
|
|
112
|
-
conditionFn = (renderContext:RenderContext) =>
|
|
112
|
+
conditionFn = (renderContext:RenderContext) =>
|
|
113
|
+
renderContext.method === "POST" && renderContext.url === this.apiPath && (renderContext.post?.api) === condition;
|
|
113
114
|
}else if(typeof condition === "function"){
|
|
114
|
-
conditionFn = async (renderContext:RenderContext) =>
|
|
115
|
+
conditionFn = async (renderContext:RenderContext) =>
|
|
116
|
+
renderContext.method === "POST" && renderContext.url === this.apiPath && (await condition(renderContext));
|
|
115
117
|
}else if(condition?.constructor == RegExp){
|
|
116
|
-
conditionFn = (renderContext:RenderContext) =>
|
|
118
|
+
conditionFn = (renderContext:RenderContext) =>
|
|
119
|
+
renderContext.method === "POST" && renderContext.url === this.apiPath && condition.test(renderContext.post?.api);
|
|
117
120
|
}else { throw "Unsupported API Condition"; }
|
|
118
121
|
this._actionList.push({
|
|
119
122
|
conditionFn,
|
|
@@ -124,11 +127,14 @@ export default class Lambder {
|
|
|
124
127
|
addPath(condition: string|ConditionFunction|RegExp, actionFn: ActionFunction):void{
|
|
125
128
|
let conditionFn: ConditionFunction = (renderContext:RenderContext) => false;
|
|
126
129
|
if(typeof condition === "string"){
|
|
127
|
-
conditionFn = (renderContext:RenderContext) =>
|
|
130
|
+
conditionFn = (renderContext:RenderContext) =>
|
|
131
|
+
renderContext.method === "GET" && renderContext.url === condition;
|
|
128
132
|
}else if(typeof condition === "function"){
|
|
129
|
-
conditionFn = async (renderContext:RenderContext) =>
|
|
133
|
+
conditionFn = async (renderContext:RenderContext) =>
|
|
134
|
+
renderContext.method === "GET" && (await condition(renderContext));
|
|
130
135
|
}else if(condition?.constructor == RegExp){
|
|
131
|
-
conditionFn = (renderContext:RenderContext) =>
|
|
136
|
+
conditionFn = (renderContext:RenderContext) =>
|
|
137
|
+
renderContext.method === "GET" && condition.test(renderContext.url);
|
|
132
138
|
}else { throw "Unsupported Path Condition"; }
|
|
133
139
|
this._actionList.push({
|
|
134
140
|
conditionFn,
|