setRegion.js 899 B

1234567891011121314151617181920
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.setRegion = void 0;
  7. const url_1 = __importDefault(require("url"));
  8. const checkConfigValid_1 = require("./checkConfigValid");
  9. function setRegion(region, internal = false, secure = false) {
  10. checkConfigValid_1.checkConfigValid(region, 'region');
  11. const protocol = secure ? 'https://' : 'http://';
  12. let suffix = internal ? '-internal.aliyuncs.com' : '.aliyuncs.com';
  13. const prefix = 'vpc100-oss-cn-';
  14. // aliyun VPC region: https://help.aliyun.com/knowledge_detail/38740.html
  15. if (region.substr(0, prefix.length) === prefix) {
  16. suffix = '.aliyuncs.com';
  17. }
  18. return url_1.default.parse(protocol + region + suffix);
  19. }
  20. exports.setRegion = setRegion;