나는 아래 2 개의 파일로 되어 있는지 확인하려면 전화를 위해서입니다. 나 약속과 콜백,나는 것을 인정해야,나는 100%에 익숙한 비동기 호출합니다.
config.js:
import rolesJson from '../../roles';
class Config{
url;
rolesList;
constructor(callback){
var baseurl = 'www.example.com/env';
fetch(baseurl)
.then(response => response.json())
.then(data => {
this.url = data.url;
getAuth(data.env);
}).catch((error) => {
});
const getAuth= (env) => {
const headers = { 'Content-Type': 'application/json' };
const options = { method: 'POST', headers, body:JSON.stringify(rolesJson(env))};
console.log("THIS BODY SHOULD NOT BE UNDEFINED", options.body);
fetch('www.example.com/auth', options)
.then(response => response.json())
.then(data => {
}).catch((error) => {
});
};
}
}
module.exports = Config;
roles.js
var roleUrl = 'www.example.com/roles';
const setEnviroment = (rolesdata,env) => {
let reqBody = {
"environment": env,
"components": rolesdata
}
console.log("REQUEST BODY CREATED", reqBody);
return req;
}
const getRoles = (env) => {
fetch(roleUrl)
.then(response => response.json())
.then(roles => {
let rolesList = [];
roles.map(x => {
const roleObj = {
name: x.name,
id: x.id,
}
rolesList.push(roleObj);
})
return setEnviroment(rolesList, env);
}).catch((error) => {
});
};
module.exports = getRoles;
고 있는지 어떻게 확인할 수 있을 때 호출하면 가져올('www.example.com/auth'옵션)옵션.몸이 정의되지 않은? 가 사용하는 비동기/여과 콜백하지 않습니다.
어떤 도움이 될 것이 매우 감사합니다.
감사