在这里,我想添加一些条件,像process.env.environment==='production'一样,只添加更多的headers值
const api_resp = await axios({
url,
method,
baseURL: `${facebookURL}/data-management/client/`,
transformResponse: [function (data) {
return data;
}],
headers: {
'Content-Type': `application/data-management-120+json`,
Authorization: `Bearer ${TOKEN}`,
},
data: payload,
});现在,如果env是如上所述的生产环境,它应该添加
'CLIENT-ID': 'xxx-xxx-xxx-xxx-xxx-xxx', 'CLIENT-SECRET': 'XXXX_XX_XXX_XXXX_XXX',
这些值在标题中,只有当process.env.environment==='production'时,否则它不会在标题中添加上面的两行。
const api_resp = await axios({
url,
method,
baseURL: `${facebookURL}/data-management/client/`,
transformResponse: [function (data) {
return data;
}],
headers: {
'Content-Type': `application/data-management-120+json`,
Authorization: `Bearer ${TOKEN}`,
'CLIENT-ID': 'xxx-xxx-xxx-xxx-xxx-xxx',
'CLIENT-SECRET': 'XXXX_XX_XXX_XXXX_XXX',
},
data: payload,
});发布于 2020-05-14 22:03:26
const headers = {
'Content-Type': `application/vnd.assaabloy.ma.credential-management-120+json`,
Authorization: `Bearer ${TOKEN}`,
}
if (process.env.environment === 'production') {
headers['CLIENT-ID'] = 'xxx';
headers['CLIENT-SECRET'] = 'xxx';
}
const api_resp = await axios({
url,
method,
baseURL: `${facebookURL}/data-management/client/`,
transformResponse: [function (data) {
return data;
}],
headers,
data: payload,
});https://stackoverflow.com/questions/61798869
复制相似问题