'getAll'的处理程序不是函数

时间:2019-04-08 12:33:27

标签: rest serverless-framework

需要在没有服务器的情况下打开它,因为它定义了get all不是一个函数吗?初始化的getall是serverless.yaml,并在handler.js中声明了该函数,但是该函数未在无服务器编译器中定义

service: api

provider:
  name: aws
  runtime: nodejs6.10 # set node.js runtime
  memorySize: 128 # set the maximum memory of the Lambdas in Megabytes
  timeout: 10 # the timeout is 10 seconds (default is 6 seconds)
  stage: dev # setting the env stage to dev, this will be visible in the routes
  region: us-east-1

functions: # add 4 functions for CRUD
  create:
    handler: handler.create # point to exported create function in handler.js
    events:
      - http:
          path: restaurant # path will be domain.name.com/dev/handler
          method: post
          cors: true
  getOne:
    handler: handler.getOne
    events:
      - http:
          path: restaurant/{id} # path will be domain.name.com/dev/handler/1
          method: get
          cors: true
  getAll:
    handler: handler.getAll # path will be domain.name.com/dev/handler
    events:
     - http:
         path: restaurant
         method: get
         cors: true

//handler.js
// Handling incoming get requests to /order
router.get(module.exports.getAll = (req,res,next) => {
    Restaurant.find().exec()
    .then(docs =>{
        console.log(docs);
        res.status(200).json(docs);
    })
    .catch(err => {
        console.log(err);
        res.status(500).json({
            error: err
        });
    });
});

0 个答案:

没有答案