无论我在哪里使用,我都在复制配置变量。我想在一种方法中通用,并在整个项目中使用该方法的变量。常见的.ts Notification(){ User.findOne({ email: data.email }, (err, user) => { if (err) { console.log(err); } else { if (user.device_info[0].platform == 'Android') { var Notification_config = new SNS({ platform: SNS.SUPPORTED_PLATFORMS.ANDROID, accessKeyId: cache.get('AMAZON_ACCESS_KEY'), secretAccessKey: cache.get('AMAZON_SECRET_KEY'), region: cache.get('AMAZON_REGION'), platformApplicationArn: 'arn:aws:sns:us-west-1:XXXXXXXX:app/GCM/Test', }); console.log("Andriod"); } else { console.log("iOS"); var Notification_config = new SNS({ platform: SNS.SUPPORTED_PLATFORMS.IOS, accessKeyId: cache.get('AMAZON_ACCESS_KEY'), secretAccessKey: cache.get('AMAZON_SECRET_KEY'), region: cache.get('AMAZON_REGION'), platformApplicationArn: 'arn:aws:sns:us-west-1:XXXXXX:app/APNS_SANDBOX/Test', sandbox: true }); } }) }abc.ts Notification_config.addUser('dev_token', JSON.stringify({ some: 'extra data' }), function (err, endpointArn) { if (err) { throw err; } // Send a simple String or data to the client Notification_config.sendMessage(endpointArn, ` sent you a request`, function (err, messageId) { if (err) { res.send(err) } req; res; console.log('Message sent, ID was: ' + messageId); });我希望变量Notification_configfromcommon.ts用于abc.ts. 我试图返回Notification_configto 方法和export default Notificationcommon.ts 并将其导入 abc.ts 但它找不到变量。有人可以帮我吗。
添加回答
举报
0/150
提交
取消