2021-12-23 23:36:33 +08:00

26 lines
837 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 阿里云 - 函数计算FC
// https://cloud.tencent.com/product/scf
import { init, server } from "./models/server";
// 阿里云函数计算 - HTTP函数
export async function handler(req: any, res: any, context: any) {
// JSON 请求
if (req.headers['content-type']?.includes('application/json')) {
let apiName = req.path.slice(1); // 去除开头的 "/"
let ret = await server.inputJSON(apiName, JSON.parse(req.body));
res.setStatusCode(ret.isSucc ? 200 : 500);
res.send(JSON.stringify(ret));
}
// 二进制请求
else {
let output = await server.inputBuffer(req.body);
res.send(Buffer.from(output));
}
}
// 阿里云函数计算 - 初始化
export async function initializer(context: unknown, callback: Function) {
await init();
callback();
}