2021-08-09 18:05:01 +08:00
|
|
|
/**
|
|
|
|
* @file 用于模拟 cfc 接口
|
|
|
|
*/
|
|
|
|
|
2023-05-05 17:13:06 +08:00
|
|
|
// @ts-ignore
|
2021-08-09 18:05:01 +08:00
|
|
|
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) => {
|
2021-08-27 14:27:44 +08:00
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
res.status(500).json({status: 500, msg: err});
|
|
|
|
} else {
|
|
|
|
res.set(result.headers);
|
2021-11-25 16:35:38 +08:00
|
|
|
if (!result.json) {
|
|
|
|
res.status(result.statusCode).send(result.body);
|
|
|
|
} else {
|
|
|
|
res.status(result.statusCode).json(JSON.parse(result.body));
|
|
|
|
}
|
2021-08-27 14:27:44 +08:00
|
|
|
}
|
2021-08-09 18:05:01 +08:00
|
|
|
});
|
|
|
|
};
|