๐ค BE TIL Day 6 0321
โฌ๏ธ Main Note
https://docs.google.com/document/d/19xINO8jcj_vMobces2Yf5BpyP-HbKUjjccS7BwBSUU0/edit
โ๏ธ Async/Await
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
- Operated while the other functions are getting executed
- It's like us using kakao-talk while downloading the game
--> we don't wait for the game to download successfully.
Synchronization
- The functions are executed one by one.
- After one function is being executed, then the user is now available to send and receive the request successfully.
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โ)
โ๏ธ Deploy
.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("์ ์ก ๋")
}
Author And Source
์ด ๋ฌธ์ ์ ๊ดํ์ฌ(๐ค BE TIL Day 6 0321), ์ฐ๋ฆฌ๋ ์ด๊ณณ์์ ๋ ๋ง์ ์๋ฃ๋ฅผ ๋ฐ๊ฒฌํ๊ณ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ๋ณด์๋ค https://velog.io/@j00b33/BE-TIL-Day-6-0321์ ์ ๊ท์: ์์์ ์ ๋ณด๊ฐ ์์์ URL์ ํฌํจ๋์ด ์์ผ๋ฉฐ ์ ์๊ถ์ ์์์ ์์ ์ ๋๋ค.
์ฐ์ํ ๊ฐ๋ฐ์ ์ฝํ ์ธ ๋ฐ๊ฒฌ์ ์ ๋ (Collection and Share based on the CC Protocol.)
์ข์ ์นํ์ด์ง ์ฆ๊ฒจ์ฐพ๊ธฐ
๊ฐ๋ฐ์ ์ฐ์ ์ฌ์ดํธ ์์ง
๊ฐ๋ฐ์๊ฐ ์์์ผ ํ ํ์ ์ฌ์ดํธ 100์ ์ถ์ฒ ์ฐ๋ฆฌ๋ ๋น์ ์ ์ํด 100๊ฐ์ ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ๋ฐ์ ํ์ต ์ฌ์ดํธ๋ฅผ ์ ๋ฆฌํ์ต๋๋ค