Skip to content

Commit 93290b4

Browse files
feat: create workflow to deploy fixes #2
1 parent a8cf421 commit 93290b4

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

.github/workflows/releaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
- name: Export dist to resources for gh-pages
5757
working-directory: ./ui
5858
run: |
59-
PUBLIC_BASE=laravel-api-auto-docs npm run export
59+
PUBLIC_BASE=laravel-api-auto-docs VITE_IS_DEMO=true npm run export
6060
6161
- name: .nojekyll
6262
run: touch ./resources/dist/.nojekyll

ui/src/stores/api.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const useApiStore = defineStore('api', () => {
77
// --- State ---
88
const apiHost = useLocalStorage('apiHost', window.location.origin);
99
const rawRoutes = ref<IGroupedRoutes[]>([]);
10+
const fullRoutes = ref<IAPIInfo[]>([]);
1011
const selectedRouteId = ref<string | null>(null);
1112
const selectedRouteDetails = ref<IAPIInfo | null>(null);
1213
const isLoadingRoutes = ref<boolean>(false);
@@ -82,9 +83,26 @@ export const useApiStore = defineStore('api', () => {
8283
async function fetchRoutes() {
8384
isLoadingRoutes.value = true;
8485
try {
85-
const response = await fetch(`${apiHost.value}/docs-api/routes`);
86+
const url = import.meta.env.VITE_IS_DEMO ? '/sample.json' : `${apiHost.value}/docs-api/routes`;
87+
const response = await fetch(url);
8688
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
87-
rawRoutes.value = await response.json();
89+
const data = await response.json();
90+
if (import.meta.env.VITE_IS_DEMO) {
91+
fullRoutes.value = data;
92+
// Group by controller for demo
93+
const grouped: { [key: string]: IAPIInfo[] } = {};
94+
data.forEach((route: IAPIInfo) => {
95+
const group = route.controller || 'Others';
96+
if (!grouped[group]) grouped[group] = [];
97+
grouped[group].push(route);
98+
});
99+
rawRoutes.value = Object.keys(grouped).map(group => ({
100+
group,
101+
routes: grouped[group].map(r => ({ id: r.uri, uri: r.uri, methods: [r.http_method] }))
102+
}));
103+
} else {
104+
rawRoutes.value = data;
105+
}
88106
} catch (err: any) {
89107
requestError.value = `Failed to fetch routes: ${err.message}. Check API Host setting.`;
90108
console.error(requestError.value);
@@ -99,9 +117,13 @@ export const useApiStore = defineStore('api', () => {
99117
// Clear previous response
100118
clearResponse();
101119
try {
102-
const response = await fetch(`${apiHost.value}/docs-api/routes/${id}`);
103-
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
104-
selectedRouteDetails.value = await response.json();
120+
if (import.meta.env.VITE_IS_DEMO) {
121+
selectedRouteDetails.value = fullRoutes.value.find(r => r.uri === id) || null;
122+
} else {
123+
const response = await fetch(`${apiHost.value}/docs-api/routes/${id}`);
124+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
125+
selectedRouteDetails.value = await response.json();
126+
}
105127
} catch (err: any) {
106128
requestError.value = `Failed to fetch route details for ${id}: ${err.message}`;
107129
console.error(requestError.value);

0 commit comments

Comments
 (0)