Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Latest commit

 

History

History
36 lines (26 loc) · 739 Bytes

controller.md

File metadata and controls

36 lines (26 loc) · 739 Bytes

请求处理

http 请求

如下面例子,无论有没有模板渲染,直接返回数据即可。

ctx: koa ctx event: ctx.request.body

module.exports = async (event, ctx) => {
    return {
        name: 'baby'
    }
};

websocket 请求

如下面例子,利用传入的 io 对象处理各种 websocket 的事件。

socket: socket.io socket 对象 ctx: 运行上下文

module.exports = (socket, ctx) => {
    socket.emit('client', { hello: 'client' });
    socket.on('server', function (data) {
        console.log(data);
    })
};