Add redirect to sub official for wechat (#132)
Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
1 parent
e453968abe
commit
0874e193d8
8 files changed
+62
-6
No files matched your search
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "patch",
|
||||
"comment": "Add support for redirect to sub offcial",
|
||||
"packageName": "@acedatacloud/nexior",
|
||||
"email": "office@acedata.cloud",
|
||||
"dependentChangeType": "patch"
|
||||
}
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { getCookie } from 'typescript-cookie';
|
||||
import { BASE_URL_HUB } from '@/constants';
|
||||
import { BASE_HOST_HUB } from '@/constants';
|
||||
import { isOfficial } from '@/utils';
|
||||
|
||||
export default {
|
||||
emits: ['click'],
|
||||
@@ -14,7 +15,7 @@ export default {
|
||||
url2: 'https://cdn.acedata.cloud/logo2.png/thumb_450x_',
|
||||
dark: getCookie('THEME') === 'dark',
|
||||
url: '',
|
||||
isOfficial: window.location.origin === BASE_URL_HUB,
|
||||
isOfficial: isOfficial(),
|
||||
interval: undefined as number | undefined
|
||||
};
|
||||
},
|
||||
|
||||
@@ -33,7 +33,8 @@ import {
|
||||
ROUTE_INDEX
|
||||
} from '@/router';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { BASE_URL_HUB } from '@/constants';
|
||||
import { BASE_HOST_HUB } from '@/constants';
|
||||
import { isOfficial } from '@/utils';
|
||||
|
||||
interface ILink {
|
||||
key: string;
|
||||
@@ -51,7 +52,7 @@ export default defineComponent({
|
||||
},
|
||||
computed: {
|
||||
isOfficial() {
|
||||
return window.location.origin === BASE_URL_HUB;
|
||||
return isOfficial();
|
||||
},
|
||||
active() {
|
||||
return this.$route.matched[0].path;
|
||||
|
||||
@@ -4,3 +4,8 @@ export const BASE_URL_PLATFORM = isTest ? 'https://platform-test.acedata.cloud'
|
||||
export const BASE_URL_HUB = isTest ? 'https://hub-test.acedata.cloud' : 'https://hub.acedata.cloud';
|
||||
export const BASE_URL_AUTH = isTest ? 'https://auth-test.acedata.cloud' : 'https://auth.acedata.cloud';
|
||||
export const BASE_URL_API = isTest ? 'https://api-test.acedata.cloud' : 'https://api.acedata.cloud';
|
||||
|
||||
export const BASE_HOST_PLATFORM = new URL(BASE_URL_PLATFORM).host;
|
||||
export const BASE_HOST_HUB = new URL(BASE_URL_HUB).host;
|
||||
export const BASE_HOST_AUTH = new URL(BASE_URL_AUTH).host;
|
||||
export const BASE_HOST_API = new URL(BASE_URL_API).host;
|
||||
+3
-1
@@ -19,11 +19,13 @@ import {
|
||||
initializeSite,
|
||||
initializeTitle,
|
||||
initializeCurrency,
|
||||
initializeExchangeRate
|
||||
initializeExchangeRate,
|
||||
initializeRedirect
|
||||
} from './utils/initializer';
|
||||
|
||||
const main = async () => {
|
||||
// async and need to await
|
||||
await initializeRedirect();
|
||||
await initializeCookies();
|
||||
await initializeToken();
|
||||
await initializeUser();
|
||||
|
||||
@@ -4,7 +4,8 @@ import { getLocale } from '@/i18n';
|
||||
import store from '@/store';
|
||||
import { IToken } from '@/models';
|
||||
import psl from 'psl';
|
||||
import { LOCALE_CURRENCY_MAPPING } from '@/constants';
|
||||
import { BASE_HOST_HUB, LOCALE_CURRENCY_MAPPING } from '@/constants';
|
||||
import { isOfficial, isSubOfficial, isWechatBrowser } from './is';
|
||||
|
||||
export const getDomain = (host: string = window.location.hostname) => {
|
||||
const parsed = psl.parse(host);
|
||||
@@ -202,3 +203,14 @@ export const initializeExchangeRate = async () => {
|
||||
console.debug('initialize exchange rate', payload);
|
||||
await store.dispatch('getExchangeRate', payload);
|
||||
};
|
||||
|
||||
export const initializeRedirect = async () => {
|
||||
if (isOfficial() && !isSubOfficial() && isWechatBrowser()) {
|
||||
console.debug('redirect to sub domain with prefix');
|
||||
// redirect from hub.acedata.cloud to dynamic date like 20240802.hub.acedata.cloud
|
||||
const date = new Date().toISOString().split('T')[0].replace(/-/g, '');
|
||||
const newUrl = window.location.href.replace(BASE_HOST_HUB, `${date}.${BASE_HOST_HUB}`);
|
||||
console.debug('redirect to', newUrl);
|
||||
window.location.href = newUrl;
|
||||
}
|
||||
};
|
||||
@@ -2,6 +2,8 @@
|
||||
* Js JSON string
|
||||
*/
|
||||
|
||||
import { BASE_HOST_HUB } from '@/constants';
|
||||
|
||||
export const isJSONString = (str: string): boolean => {
|
||||
try {
|
||||
JSON.parse(str);
|
||||
@@ -10,3 +12,24 @@ export const isJSONString = (str: string): boolean => {
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the string is wechat browser
|
||||
*/
|
||||
export const isWechatBrowser = (): boolean => {
|
||||
return /micromessenger/i.test(navigator.userAgent);
|
||||
};
|
||||
|
||||
/**
|
||||
* isOfficial
|
||||
*/
|
||||
export const isOfficial = (): boolean => {
|
||||
return window.location.host.includes(BASE_HOST_HUB);
|
||||
};
|
||||
|
||||
/**
|
||||
* isSubOfficial
|
||||
*/
|
||||
export const isSubOfficial = (): boolean => {
|
||||
return isOfficial() && window.location.host !== BASE_HOST_HUB;
|
||||
};
|
||||
@@ -1,10 +1,15 @@
|
||||
import { ISite } from '@/models';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { isOfficial } from './is';
|
||||
import { BASE_URL_HUB } from '@/constants';
|
||||
|
||||
export const getSiteOrigin = (site?: ISite) => {
|
||||
if (site?.origin) {
|
||||
return site?.origin;
|
||||
}
|
||||
if (isOfficial()) {
|
||||
return BASE_URL_HUB;
|
||||
}
|
||||
const host = window.location.host;
|
||||
// if localhost, try to generate uuid
|
||||
if (host.includes('localhost')) {
|
||||
|
||||
Reference in new issue
Block a user