Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method not allowed with method POST #174

Open
gil2gm opened this issue Feb 27, 2021 · 6 comments
Open

Method not allowed with method POST #174

gil2gm opened this issue Feb 27, 2021 · 6 comments
Assignees

Comments

@gil2gm
Copy link

gil2gm commented Feb 27, 2021

Hello, i need your help!

I have problem with the api, i use register like this

//------------------------------------------------------- index.js
const api = require('lambda-api')({ version: 'v1.0', base: 'v1' });
api.register(require('./routes'), { prefix: '/bot' });
//------------------------------------------------------- 

i not have problem with the method get, my problem are the methods POST, i proof the two forms, but any working

//------------------------------------------------------- routes.js
module.exports = (api, opts) => {
  api.get('/list', bot.list);
  api.post('/selector', bot.selector);
  api.METHOD('post','/validator_response', bot.validator_response);
  api.post('/hermes', bot.hermes);
};
//-------------------------------------------------------

Always i have the same response:

Response
{
  "statusCode": 200,
  "headers": {
    "content-type": "application/json"
  },
  "body": "{\"error\":\"Method not allowed\"}"
}
@stawecki
Copy link

stawecki commented Mar 1, 2021

Hi Gilberto,
The sample you've provided seems to work fine, when testing sample path /v1/bot/selector.
Perhaps the issue is somewhere else.

  • Are you sure you're passing the bot.selector/bot.hermes handlers correctly?
  • Are you sure you're testing the correct path?
  • What are you using for invoking test events?
  • Have you also tried printing all the routes with: api.routes(true);

Good luck!

@slootjes
Copy link

slootjes commented Mar 4, 2021

Created separate issue #179 for this as it seems to be a different issue.

@gil2gm
Copy link
Author

gil2gm commented Mar 27, 2021

I found the problem, lambda-api not working with version 2.0 of api-gateway

request.js
 // Set the method
    this.method = this.app._event.httpMethod ? this.app._event.httpMethod.toUpperCase() : 'GET'

api-gateway aws v1.0

{
  version: '1.0',
  httpMethod: 'POST',

api-gateway aws v2.0

{
  "version": "2.0",
  "requestContext": {
    "http": {
      "method": "POST",

Solution 1: configure api gateway aws with the version 1.0 or
Solution 2: temporal, set in handler function

if(event.version === "2.0"){
   event.httpMethod = event.requestContext.http.method;
  }

@jeremydaly
Copy link
Owner

v0.11 supports Payload V2 and should be available shortly.

@capndave
Copy link

capndave commented Oct 7, 2022

@jeremydaly we're unable to POST (and perhaps to put?) when running locally using Node 16, but Node 14 works fine. Is that consistent with the Payload V2 thing? Could our failure be related to the type of payload?

@jeremydaly
Copy link
Owner

Strange the Node version would be causing a problem unless it has something to do with the body parser. Shouldn't have anything to do with the payload format.

@naorpeled naorpeled self-assigned this Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants