Skip to content

Commit 4c61c13

Browse files
committed
fix: require hosted config before enabling hosted mode
1 parent 4133cce commit 4c61c13

3 files changed

Lines changed: 70 additions & 68 deletions

File tree

src/composables/useHostedMode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type HostedWindow = Window & {
1313

1414
export const getHostedConfig = () => (window as HostedWindow).__SPOOLMAN_HOSTED__ ?? null;
1515

16-
export const isHostedMode = () => Boolean(getHostedConfig() || new URLSearchParams(window.location.search).get("spoolman_hosted"));
16+
export const isHostedMode = () => Boolean(getHostedConfig());
1717

1818
export const getHostedTheme = () => {
1919
const hostedTheme = (window as HostedWindow).__SPOOLMAN_HOSTED_THEME__;

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createApp } from "vue";
22
import { createI18n } from "vue-i18n";
3-
import router from "./router";
3+
import { createAppRouter } from "./router";
44
import App from "./App.vue";
55
import "./styles.css";
66
import de from "./locales/de.json";
@@ -66,6 +66,7 @@ const bootstrap = async () => {
6666
});
6767

6868
setupTheme();
69+
const router = createAppRouter();
6970

7071
// Hosted mode relies on the Spoolman shell for analytics and server discovery.
7172
if (import.meta.env.MODE !== "development" && !hostedConfig) {

src/router/index.ts

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,78 +5,79 @@ import ProjectsView from '@/views/ProjectsView.vue';
55
import ProjectDetailView from '@/views/ProjectDetailView.vue';
66
import { isHostedMode } from '@/composables/useHostedMode';
77

8-
const hostedMode = isHostedMode();
98
const hostedRoot = '/app/swatch';
109
const hostedTitle = 'Filament Swatch';
1110
const standaloneTitle = 'Spool Swatch';
12-
const titlePrefix = hostedMode ? hostedTitle : standaloneTitle;
11+
export const createAppRouter = () => {
12+
const hostedMode = isHostedMode();
13+
const titlePrefix = hostedMode ? hostedTitle : standaloneTitle;
1314

14-
const router = createRouter({
15-
history: createWebHistory(import.meta.env.BASE_URL),
16-
routes: [
17-
hostedMode
18-
? {
19-
path: '/',
20-
redirect: hostedRoot,
21-
}
22-
: {
23-
path: '/',
24-
name: 'landing',
25-
component: LandingPage,
26-
meta: {
27-
title: `${titlePrefix} - Your 3D Printing Filament Color Browser`
15+
const router = createRouter({
16+
history: createWebHistory(import.meta.env.BASE_URL),
17+
routes: [
18+
hostedMode
19+
? {
20+
path: '/',
21+
redirect: hostedRoot,
2822
}
29-
},
30-
{
31-
path: '/app',
32-
component: MainApp,
33-
redirect: hostedRoot,
34-
children: [
35-
{
36-
path: 'swatch',
37-
name: 'swatch',
38-
component: () => import('@/views/FilamentsView.vue'),
39-
meta: {
40-
title: `${titlePrefix} - Browse Your Collection`
23+
: {
24+
path: '/',
25+
name: 'landing',
26+
component: LandingPage,
27+
meta: {
28+
title: `${titlePrefix} - Your 3D Printing Filament Color Browser`
29+
}
30+
},
31+
{
32+
path: '/app',
33+
component: MainApp,
34+
redirect: hostedRoot,
35+
children: [
36+
{
37+
path: 'swatch',
38+
name: 'swatch',
39+
component: () => import('@/views/FilamentsView.vue'),
40+
meta: {
41+
title: `${titlePrefix} - Browse Your Collection`
42+
}
43+
},
44+
{
45+
path: 'projects',
46+
name: 'projects',
47+
component: ProjectsView,
48+
meta: {
49+
title: `${titlePrefix} - Projects`
50+
}
51+
},
52+
{
53+
path: 'projects/:id',
54+
name: 'project-detail',
55+
component: ProjectDetailView,
56+
meta: {
57+
title: `${titlePrefix} - Project Details`
58+
}
4159
}
42-
},
43-
{
44-
path: 'projects',
45-
name: 'projects',
46-
component: ProjectsView,
47-
meta: {
48-
title: `${titlePrefix} - Projects`
49-
}
50-
},
51-
{
52-
path: 'projects/:id',
53-
name: 'project-detail',
54-
component: ProjectDetailView,
55-
meta: {
56-
title: `${titlePrefix} - Project Details`
57-
}
58-
}
59-
]
60-
},
61-
// Catch-all redirect for unknown routes
62-
{
63-
path: '/:pathMatch(.*)*',
64-
redirect: hostedMode ? hostedRoot : '/'
65-
}
66-
],
67-
scrollBehavior(to, from, savedPosition) {
68-
if (savedPosition) {
69-
return savedPosition;
70-
} else {
71-
return { top: 0 };
60+
]
61+
},
62+
// Catch-all redirect for unknown routes
63+
{
64+
path: '/:pathMatch(.*)*',
65+
redirect: hostedMode ? hostedRoot : '/'
66+
}
67+
],
68+
scrollBehavior(to, from, savedPosition) {
69+
if (savedPosition) {
70+
return savedPosition;
71+
} else {
72+
return { top: 0 };
73+
}
7274
}
73-
}
74-
});
75+
});
7576

76-
// Update document title on route change
77-
router.beforeEach((to, from, next) => {
78-
document.title = (to.meta.title as string) || titlePrefix;
79-
next();
80-
});
77+
router.beforeEach((to, from, next) => {
78+
document.title = (to.meta.title as string) || titlePrefix;
79+
next();
80+
});
8181

82-
export default router;
82+
return router;
83+
};

0 commit comments

Comments
 (0)