Skip to content

Commit 8dd01bb

Browse files
authored
When examples are disabled, don't show the examples button (#19)
1 parent 0186e7c commit 8dd01bb

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

client/src/App.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<router-link class="navbar-brand" to="/">{{ siteTitle }}</router-link>
77
<div class="d-flex gap-2 align-items-center">
88
<router-link to="/" class="btn btn-sm btn-outline-secondary">Home</router-link>
9-
<router-link to="/examples" class="btn btn-sm btn-outline-secondary">Examples</router-link>
9+
<router-link v-if="showExamples" to="/examples" class="btn btn-sm btn-outline-secondary">Examples</router-link>
1010
<button class="btn btn-sm btn-outline-secondary" @click="toggleTheme">
1111
{{ theme === "dark" ? "Light" : "Dark" }}
1212
</button>
@@ -29,6 +29,7 @@ import { useRoute } from "vue-router";
2929
3030
const siteTitle = ref("pev2");
3131
const customBanner = ref("");
32+
const showExamples = ref(false);
3233
3334
const route = useRoute();
3435
const copied = ref(false);
@@ -70,6 +71,7 @@ onMounted(async () => {
7071
const config = await res.json();
7172
siteTitle.value = config.siteTitle;
7273
customBanner.value = config.customBanner || "";
74+
showExamples.value = !!config.showExamples;
7375
document.title = `${config.siteTitle} — PostgreSQL EXPLAIN Visualizer`;
7476
}
7577
} catch {

client/src/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const router = createRouter({
1010
{ path: "/examples", component: ExamplesView },
1111
{ path: "/plan/:id", component: PlanView },
1212
{ path: "/example/:name", component: PlanView, meta: { isExample: true } },
13+
{ path: "/:pathMatch(.*)*", redirect: "/" },
1314
],
1415
});
1516

client/src/views/ExamplesView.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,28 @@
3737

3838
<script setup lang="ts">
3939
import { ref, onMounted } from "vue";
40+
import { useRouter } from "vue-router";
4041
4142
interface ExamplePlan {
4243
name: string;
4344
title: string;
4445
}
4546
47+
const router = useRouter();
4648
const examples = ref<ExamplePlan[]>([]);
4749
const loading = ref(true);
4850
4951
onMounted(async () => {
5052
try {
5153
const res = await fetch("/api/examples");
52-
if (res.ok) {
53-
examples.value = await res.json();
54+
if (!res.ok) {
55+
router.replace("/");
56+
return;
5457
}
58+
examples.value = await res.json();
5559
} catch {
56-
// ignore
60+
router.replace("/");
61+
return;
5762
} finally {
5863
loading.value = false;
5964
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pev2-on-s3",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"private": true,
55
"type": "module",
66
"scripts": {

server/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ router.get("/api/config", (_req, res) => {
2323

2424
router.get("/api/examples", (_req, res) => {
2525
if (!config.examples.enabled) {
26-
res.json([]);
26+
res.status(403).json({ error: "Examples are not enabled" });
2727
return;
2828
}
2929
try {

0 commit comments

Comments
 (0)