Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
const ts = await loadTs(cache.file, { tmp: true });
func = ts.module;
} catch (error) {
this.logger.error(error);
res.statusCode = 500;
res.write(error.message);
res.end();
return reject(error);
}
}
}
try {
if (!cache.handler) {
// 读取云函数配置并写入缓存
func.config = loadConfig(this.root, path).development;
// eslint-disable-next-line require-atomic-updates
cache.handler = func.export().handler;
}
let body = '';
req.on('readable', function () {
body += req.read() || '';
});
req.on('end', async () => {
const uri = URL.parse(req.url!);
let data;
try {
data = await cache.handler({
headers: req.headers,
constructor (data: DeployData) {
data.name = data.filename.replace(data.root, '').replace('.func.ts', '').replace(/^\/?[^/]+\//, '').replace(/\/$/, '');
data.version = new Date().toLocaleString('zh-CN', {
hour12: false,
timeZone: 'Asia/Shanghai',
}).replace(/(\/|:|\s)/g, '_');
data.logger = new Logger('Deployer');
const Config = loadConfig(data.root, data.filename);
if (!data.env) {
data.env = process.env.FaasEnv || Config.defaults.deploy.env;
}
data.config = Config[data.env!];
if (!data.config) {
throw Error(`Config load failed: ${data.env}`);
}
data.tmp = `${data.root}/tmp/${data.env}/${data.name}/${data.version}/`;
data.tmp.split('/').reduce(function (acc: string, cur: string) {
acc += '/' + cur;
if (!existsSync(acc)) {