// Require the framework
import Fastify from "fastify";
// Instantiate Fastify with some config
const app = Fastify({
logger: true,
});
// Register your application as a normal plugin.
app.register(routes);
export default async (ctx) => {
const req = ctx.request
const res = ctx.response
console.log(req)
console.log(res)
await app.ready();
app.server.emit('request', req, res);
}
async function routes(fastify, options) {
fastify.get('/', async (request, reply) => {
return { hello: 'world' }
})
}
实验代码如上,可以将云函数请求拦截在入口或者二次转发。
原理大概参考路由的上下文,将ctx参数传到fastify上下文,其他框架也可以实现类似的效果.
探索之路,仅供参考!