β¬οΈ Main Note
https://docs.google.com/document/d/19xINO8jcj_vMobces2Yf5BpyP-HbKUjjccS7BwBSUU0/edit
Two computers are requesting and responsing to each other to deliver the data.
But sometimes, the request isn't sent properly.
--> This is because the user requested to fetch the information even before the data is fully uploaded to the data base.
To solve this problem, here, we use async/await.
Asynchronization
Javascript is in async way.
--> Source code is executed line by line.
--> After a line of code is executed, the next code is being executed.
// ========== λκΈ°νμ ==========
const data = axios.get(βhttps://koreanjson.comp/posts/1β)
console.log(data) //promise
// ========== λΉλκΈ°λ₯Ό λκΈ°λ‘ λ°κΎΈκΈ° ==========
async function createBoard(){
const data = await axios.get(βhttps://koreanjson.comp/posts/1β)
.env
--> file
process.env.λ³μλͺ
--> how to import
Since .env files are for important data, we rarely git push to git hub with the source code.
// ========== API Create ==========
app.post('/tokens/phone', (req, res) => {
// facade pattern makes the efficiency go higher
const phone = req.body.phoneNumber
const isValid = getPhoneNumber(phone)
if (isValid){
const myToken = getToken()
sendTokenToSMS(phone, myToken)
res.send("μΈμ¦μλ£ " + myToken)
}
})
// ========== API Structure ==========
export async function sendTokenToSMS (fff, ggg){
// console.log(fff + " λ²νΈλ‘ μΈμ¦λ²νΈ " + ggg + "λ₯Ό μ μ‘ν©λλ€")
const appKey = process.env.SMS_APP_KEY
const XSecretKey = process.env.SMS.X_SECRET_KEY
const sender = process.env.SNS_SENDER
const result = await axios.post( `https://api-sms.cloud.toast.com/sms/v3.0/${appKey}/WNgOBwLIMMiRMbfw/sender/sms`,{ //endpoint
// data
body: `γ
γ
γ
γ
, μΈμ¦λ²νΈλ [${ggg}]μ`,
sendNo: sender, // 보λ΄λ μ¬λ
recipientList:[
// λ°λ μ¬λ (λμμ μ¬λ¬λͺ
μκ² λ³΄λΌ μ μκΈ°μ λκ΄νΈ μμ κ°μ²΄ ννλ‘ λ£μ΄μ€)
{internationalRecipientNo: fff}
]
},{
headers: {
//config - μ€μ νμΌ
"Content-Type": "application/json;charset-URF-8",
"X-Secret-Key": XSecretKey
}
})
console.log(result)
console.log("μ μ‘ λ")
}