나의 개발일지(김지헌)
공부 본문
NODE_ENV 선언후 config 객체를 만듬 -> config[env](선언객체[키값])실행시 선언해둔 NODE_ENV값에 따라 config에서 찾아서 갑을 넣어줌
const NODE_ENV = "dev"
const env = NODE_ENV
console.log(env)
const config = {
production : {
username : "ㅎㅇ",
password : "1234",
database : "333",
host : "1234",
dialect : "ㅇㅎㅇㅎㅇ"
},
dev : {
username : "sed",
password : "1asdf",
database : "3asdf",
host : "asdfasd",
dialect : "dfaasdfsda"
}
}
const { username, password, database, host, dialect } = config[env];
class 선언후 new 클래스() 하면 인스턴스화 되면서 맞는 클래스에 맞춰 값이 들어감
class options implements Options {
dialect!: 'mysql';
username!: string;
password!: string;
host!:string;
}
//데이터베이스 옵션
const createDBOptions = new options();
createDBOptions.username = process.env.DB_USER || 'root';
createDBOptions.password = process.env.DB_PASSWORD || 'your password';
createDBOptions.host = process.env.DB_HOST!;
createDBOptions.dialect = 'mysql';
createDBOptions.host = process.env.DB_HOST!;
/*
패치함수로 요청 보내기
기본적으로 fetch함수는 get 요청이므로 옵션 필요없다
*/
//GET
const url = "https://www.dafd.com"
fetch(url)
.then((response) =>response.json()) //json으로 바꿔주고
.then((data) => console.log(data)) //결과값을 여기서 볼 수 있다.
.catch((error) => console.log("error:", error));
//POST
/* 헤더 (백 프론트 규칙에 따라 헤더에 토큰 및 쿠키로 토큰 보내기)*/
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
//myHeaders.append("Authorization", "Bearer eyjj");
//myHeaders.append("refreshToken", "Bearer eyjj");
----------OR---------------
const myHeaders = {
'Content-Type': 'application/json;charset=UTF-8' ,
Accept : 'application/json' }
/* 바디 양식을 잘 맞춰줘야한다.*/
const raw = JSON.stringify({
email: "sadfqqs@gmail.com",
password: "@Mi1212312"
});
-------------OR-----------
const num1 = Math.floor(Math.random() * 100)
const raw = JSON.stringify({
email: `yo${num1}${num1}@gmail.com`,
password: "@Umm1231234"
});
/* 옵션 */
const requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
/* 결과 */
fetch("https://K.aws.com/users/signup/check", requestOptions)
.then(res => res.json())
.then(result => console.log(result))
.catch(error => console.log('error', error));
----------------OR---------------------
net::err_aborted 400 오류 뜰시 텍스트로 받아오기
fetch("https://K.aws.com/users/signup/check", requestOptions)
.then(res =>{
res.text().then(result => console.log(result))
})
.catch(error => console.log('error', error));
'공부' 카테고리의 다른 글
MYSQL 우분투 설치 및 명령어 (0) | 2023.03.13 |
---|---|
리눅스 명령어 및 EC2설정 NginX (0) | 2023.03.13 |
노션 API (0) | 2023.03.09 |
S3 버킷, Route53, CloudFront 연결해보기 + HTTPS통신 까지 (0) | 2023.03.07 |
Route 53 (0) | 2023.03.06 |