mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-15 17:31:18 +08:00
d6461ced11
* chore: 修复 ts 报错,并加入 pr 检测 * 把类型检测放在前面 * 调整一下顺序 * 类型调整 * 设置 build 编译顺序 * 设置 build 编译顺序
37 lines
815 B
JavaScript
37 lines
815 B
JavaScript
/**
|
|
* @file 用于模拟 cfc 接口
|
|
*/
|
|
|
|
// @ts-ignore
|
|
const cfcHandler = require('./cfc/index').handler;
|
|
|
|
module.exports = function (req, res) {
|
|
const subpath = (req.originalUrl || req.url).replace(
|
|
/^\/(api\/mock2|api)\/|\?.*$/g,
|
|
''
|
|
);
|
|
const mockEvent = {
|
|
queryStringParameters: req.query,
|
|
pathParameters: {
|
|
subpath
|
|
},
|
|
headers: req.headers,
|
|
body: req.body
|
|
};
|
|
const mockContext = {};
|
|
|
|
cfcHandler(mockEvent, mockContext, (err, result) => {
|
|
if (err) {
|
|
console.error(err);
|
|
res.status(500).json({status: 500, msg: err});
|
|
} else {
|
|
res.set(result.headers);
|
|
if (!result.json) {
|
|
res.status(result.statusCode).send(result.body);
|
|
} else {
|
|
res.status(result.statusCode).json(JSON.parse(result.body));
|
|
}
|
|
}
|
|
});
|
|
};
|