lambder 2.0.14 → 2.0.15

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/Lambder.js CHANGED
@@ -120,10 +120,9 @@ export default class Lambder {
120
120
  }
121
121
  addRoute(condition, actionFn) {
122
122
  this.actionList.push({
123
- conditionFn: (ctx) => (ctx.method === "GET" &&
124
- ((typeof condition === "string" && this.testPatternMatch(condition, ctx.path)) ||
125
- (typeof condition === "function" && condition(ctx)) ||
126
- (condition?.constructor == RegExp && condition.test(ctx.path)))),
123
+ conditionFn: (ctx) => (((typeof condition === "string" && this.testPatternMatch(condition, ctx.path)) ||
124
+ (typeof condition === "function" && condition(ctx)) ||
125
+ (condition?.constructor == RegExp && condition.test(ctx.path)))),
127
126
  actionFn: async (ctx, resolver) => {
128
127
  if (typeof condition === "string") {
129
128
  ctx.pathParams = this.getPatternMatch(condition, ctx.path);
@@ -139,10 +138,9 @@ export default class Lambder {
139
138
  }
140
139
  addSessionRoute(condition, actionFn) {
141
140
  this.actionList.push({
142
- conditionFn: (ctx) => (ctx.method === "GET" &&
143
- ((typeof condition === "string" && this.testPatternMatch(condition, ctx.path)) ||
144
- (typeof condition === "function" && condition(ctx)) ||
145
- (condition?.constructor == RegExp && condition.test(ctx.path)))),
141
+ conditionFn: (ctx) => (((typeof condition === "string" && this.testPatternMatch(condition, ctx.path)) ||
142
+ (typeof condition === "function" && condition(ctx)) ||
143
+ (condition?.constructor == RegExp && condition.test(ctx.path)))),
146
144
  actionFn: async (ctx, resolver) => {
147
145
  if (typeof condition === "string") {
148
146
  ctx.pathParams = this.getPatternMatch(condition, ctx.path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambder",
3
- "version": "2.0.14",
3
+ "version": "2.0.15",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/Lambder.ts CHANGED
@@ -163,7 +163,6 @@ export default class Lambder<TSessionData = any, _TContract extends Record<strin
163
163
  addRoute(condition: Path|ConditionFunction|RegExp, actionFn: ActionFunction): this {
164
164
  this.actionList.push({
165
165
  conditionFn: (ctx:LambderRenderContext<any>) => (
166
- ctx.method === "GET" &&
167
166
  (
168
167
  (typeof condition === "string" && this.testPatternMatch(condition, ctx.path)) ||
169
168
  (typeof condition === "function" && condition(ctx)) ||
@@ -187,7 +186,6 @@ export default class Lambder<TSessionData = any, _TContract extends Record<strin
187
186
  addSessionRoute(condition: Path|ConditionFunction|RegExp, actionFn: SessionActionFunction<TSessionData>): this {
188
187
  this.actionList.push({
189
188
  conditionFn: (ctx:LambderRenderContext<any>) => (
190
- ctx.method === "GET" &&
191
189
  (
192
190
  (typeof condition === "string" && this.testPatternMatch(condition, ctx.path)) ||
193
191
  (typeof condition === "function" && condition(ctx)) ||
@@ -518,13 +518,13 @@ describe('Routes - Wildcard and Catch-all Routes', () => {
518
518
  });
519
519
 
520
520
  describe('Routes - Method Filtering', () => {
521
- it('should only match GET requests', async () => {
521
+ it('should match all HTTP methods when no method is specified', async () => {
522
522
  const lambder = new Lambder({
523
523
  publicPath: './public',
524
524
  apiPath: '/api'
525
525
  })
526
526
  .addRoute('/resource', (ctx, res) => {
527
- return res.html('GET Response');
527
+ return res.html(`${ctx.method} Response`);
528
528
  });
529
529
 
530
530
  const handler = lambder.getHandler();
@@ -534,9 +534,10 @@ describe('Routes - Method Filtering', () => {
534
534
  const getResult = await handler(getEvent, createMockContext());
535
535
  expect(Buffer.from(getResult.body || '', 'base64').toString()).toBe('GET Response');
536
536
 
537
- // POST should not match routes (should hit fallback)
537
+ // POST should also work (no method restriction)
538
538
  const postEvent = createMockEvent('/resource', 'POST');
539
539
  const postResult = await handler(postEvent, createMockContext());
540
- expect(postResult.statusCode).toBe(204); // Default fallback
540
+ expect(postResult.statusCode).toBe(200);
541
+ expect(Buffer.from(postResult.body || '', 'base64').toString()).toBe('POST Response');
541
542
  });
542
543
  });