juanjoDiaz/serverless-middleware

No matching handler found for "path to files"

ADrejta opened this issue · 4 comments

When using serverless-middleware Im getting this error when i want to start serverless offline

 No matching handler found for 'src/middlewares/verifyToken.verifyToken,src/functions/resetPassword/resetPassword'

Here is how i have it setup at the moment:

serverless.yml:

service: app

# Create an optimized package for our functions
package:
  individually: true

plugins:
  - serverless-webpack # Package our functions with Webpack
  - serverless-middleware
  - serverless-offline
  - serverless-dotenv-plugin # Load .env as environment variables

provider:
  name: aws
  runtime: nodejs12.x
  stage: dev
  region: eu-west-1
 

functions:
  resetPassword: ${file(src/functions/resetPassword/resetPassword.yml):resetPassword}

resetPassword.yml

resetPassword: 
  handler:
    - src/middlewares/verifyToken.verifyToken
    - src/functions/resetPassword/resetPassword.resetExport
  events: 
    - http:
        path: resetPassword
        method: put
    - schedule: 
        rate: rate(5 minutes)
        enabled: true

verifyToken.ts

const verifyToken = async (event, context) => {
     // my logic here
};

export { verifyToken };

resetPassword.ts

const resetPassword = async (event) => {
  // after middleware logic here
};

const resetExport = runWarm(resetPassword);

export { resetExport };

When i leave only one handler the error does not appear, however then i cannot use the middleware as described in the docs.

Serverless-offilne version: 6.8.0
Serverless-middleware version: 0.0.10
Node version: 14.0.0

P.S: When i try to do it with the then: keyword like this:

resetPassword: 
  handler:
    - src/middlewares/verifyToken.verifyToken
    - then: src/functions/resetPassword/resetPassword.resetExport
  events: 
    - http:
        path: resetPassword
        method: put
    - schedule: 
        rate: rate(5 minutes)
        enabled: true

I'm getting this error:

TypeError: handler.substr is not a function

Hi,

Sorry for the very late response.

The problem is that the webpack plugin is trying to process the handlers before middleware plugin processes them into a single handler. You must declare this plugin before the webpack one.

Using then or not, should make absolutely no difference. I suspect that the problem is also with the webpack plugin being declared earlier in the chain.

Closing since there is no response and a solution has been given.

Feel free to reopen if there is anything else to look at.

I have the same problem.
I use this plugins:

plugins:
  - serverless-middleware
  - serverless-webpack
  - serverless-domain-manager
  - serverless-webpack-layers
  - serverless-offline
  - serverless-plugin-datadog
  - serverless-prune-plugin
Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              14.15.4
     Framework Version:         2.30.3 (local)
     Plugin Version:            4.5.1
     SDK Version:               4.2.0
     Components Version:        3.7.5

This is a simple problem, when I run my serverless offline I use sls offline only, but, if you use server offline start it's work!

For more information: https://github.com/dherault/serverless-offline#usage-with-serverless-dynamodb-local-and-serverless-webpack-plugin