Fix init issue for site (#50)
This commit is contained in:
1 parent
beb85b8ebd
commit
223e14222d
6 files changed
+57
-31
No files matched your search
@@ -130,5 +130,11 @@ export const initializeFavicon = async () => {
|
||||
* Need to initialize site before render contents
|
||||
*/
|
||||
export const initializeSite = async () => {
|
||||
await store.dispatch('initializeSite');
|
||||
await store.dispatch('getSite');
|
||||
// after getSite, the site should have been set
|
||||
const site = store.state.site;
|
||||
// if site is not set, try to initialize site
|
||||
if (!site) {
|
||||
await store.dispatch('initializeSite');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
import { ISite } from '@/models';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
export const getSiteOrigin = (site?: ISite) => {
|
||||
if (site?.origin) {
|
||||
return site?.origin;
|
||||
}
|
||||
const host = window.location.host;
|
||||
// if localhost, try to generate uuid
|
||||
if (host.includes('localhost')) {
|
||||
// generate uuid
|
||||
const randomId = uuid();
|
||||
return `http://localhost-${randomId}`;
|
||||
} else {
|
||||
return window.location.origin;
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user