最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 12浏览 0评论

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

将属性从文件加载到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. 暂无评论