Skip to content

Commit 67d4e33

Browse files
committed
update openapi link and routes
1 parent dea8da3 commit 67d4e33

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "tsc -b && vite build",
99
"lint": "biome check",
1010
"preview": "vite preview",
11-
"generate": "openapi-typescript http://localhost:8787/openapi -o src/api.g.ts"
11+
"generate": "openapi-typescript http://localhost:8787/api/openapi.json -o src/api.g.ts"
1212
},
1313
"dependencies": {
1414
"@awesomeqr/react": "0.1.2-rc.0",

app/src/controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,16 @@ export async function deleteWithToken(id: string, token: string) {
125125
}
126126

127127
export async function info(id: string) {
128-
const { data, error } = await client.GET("/api/info/{id}", {
128+
const { data, error, response } = await client.GET("/api/info/{id}", {
129129
params: {
130130
path: { id },
131131
},
132132
});
133133

134+
if (response.status === 404) {
135+
return null;
136+
}
137+
134138
if (error !== undefined) {
135139
console.error("Failed to get info:", error);
136140
throw new Error(`Failed to get info: ${error}`);

app/src/views/About.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Button, Container, Text, Typography } from "@mantine/core";
2+
import { ArrowRight } from "react-feather";
23
import Header from "../components/Header";
34

45
function About() {
@@ -52,7 +53,20 @@ function About() {
5253
everyone, I please ask that you use the API for small projects and{" "}
5354
<a href="https://jakew.me/about">contact me</a> first for any bigger projects.
5455
</p>
55-
<Button component="a" href="/docs">
56+
<p>
57+
API documentation is available at the link below, and you can also access the OpenAPI specification at{" "}
58+
<a href="/api/openapi.json">
59+
<code>/api/openapi.json</code>
60+
</a>
61+
.
62+
</p>
63+
<Button
64+
component="a"
65+
href="/docs"
66+
variant="light"
67+
style={{ textDecoration: "none" }}
68+
rightSection={<ArrowRight size={16} />}
69+
>
5670
See API Documentation
5771
</Button>
5872
</Typography>

app/src/views/View.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ function View() {
1818
if (link === undefined) return;
1919

2020
getInfo(link)
21-
.then((data) => setData(data))
21+
.then((data) => {
22+
if (data === null) {
23+
setNotFound(true);
24+
} else {
25+
setData(data);
26+
}
27+
})
2228
.catch((err) => {
2329
if (err.response && err.response.status == 404) {
2430
setNotFound(true);

worker/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const withDb: MiddlewareHandler = async (c, next) => {
4444
app.use("*", cors());
4545

4646
app.get(
47-
"/openapi",
47+
"/api/openapi.json",
4848
openAPISpecs(app, {
4949
documentation: {
5050
info: {
@@ -69,7 +69,7 @@ app.get(
6969
app.get(
7070
"/docs",
7171
Scalar({
72-
url: "/openapi",
72+
url: "/api/openapi.json",
7373
theme: "purple",
7474
pageTitle: "VH7 API Docs",
7575
}),

0 commit comments

Comments
 (0)