index.ts 630 B

12345678910111213141516171819
  1. import { REQUEST_CONFIG } from '../../../config';
  2. /** 获取域名 useLocal: 开发用-是否不用代理的域名,用本地域名 */
  3. export const useDomain = (useLocal = false) => {
  4. let origin = '',
  5. pathname = '';
  6. if (process.env.NODE_ENV == 'development' && !useLocal) {
  7. const [domain] = REQUEST_CONFIG.BASE_URL.match(
  8. /^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/
  9. );
  10. origin = domain;
  11. pathname = REQUEST_CONFIG.BASE_URL;
  12. } else {
  13. origin = location.origin;
  14. pathname = location.pathname;
  15. }
  16. const hasSuffix = pathname.match(/\/KasiteWeb\//);
  17. return `${origin}${hasSuffix ? '/KasiteWeb' : ''}`;
  18. };