最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

将属性从文件加载到axios实例

运维笔记admin16浏览0评论

将属性从文件加载到axios实例

将属性从文件加载到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结构。

发布评论

评论列表(0)

  1. 暂无评论