将属性从文件加载到axios实例
我如何将axios配置从文件加载到axios实例
index.js
var config = require("./config")
const api = axios.create({
baseURL: `${token}`,
httpsProxyAgent:
config.proxy != undefined ? new httpsProxyAgent(config.proxy) : null
});
config.js,完整文件
var config = {
development: {
server: {
host: "localhost",
port: 3000
},
bot: {
token: "token",
webhook: ""
},
proxy: "http://url:port"
}
};
module.exports = config;
回答如下:尝试这种方式,
config.js
module.exports = {
proxy: "https://example"
}
现在,您可以从文件访问属性,因为它具有JSON结构。