Serverless framework v1 - multiple resources in one service

前端 未结 3 1902
清歌不尽
清歌不尽 2021-01-20 14:33

I have two resources, games and players, both have crud functions. Are these supposed to be in the same serverless service? I would like to separate them, but how do I then

3条回答
  •  自闭症患者
    2021-01-20 15:06

    In your example you would want to keep them in the same serverless framework. I would create two files player.js and game.js in src/controllers to seperate out the logic.

    You can setup serverless with the following YAML file

    functions:
      player_info:
        handler: src/controllers/player.info
        events:
        - http:
            path: player # path in the url
            method: get
      player_create:
        handler: src/controllers/player.create
        events:
        - http:
            path: player # path in the url
            method: post
      player_delete:
        handler: src/controllers/player.delete
        events:
        - http:
            path: player # path in the url
            method: delete
      game_info:
        handler: src/controllers/game.info
        events:
        - http:
            path: player # path in the url
            method: get
      game_create:
        handler: src/controllers/game.create
        events:
        - http:
            path: player # path in the url
            method: post
      game_delete:
        handler: src/controllers/game.delete
        events:
        - http:
            path: player # path in the url
            method: delete
    

提交回复
热议问题