Commit 40611ea022

40611ea02242cb3fcb81c0ca10d3d46be2d4394b

parent: 3e2d719d47

Unsigned

Alicia Sykes <alicia@omg.lol> · 2024-03-08 18:09 UTC

Updates API landing for Hono on CF workers for Swagger

Layout: unified · split

api/src/api.ts +6 −20
@@ -9,34 +9,20 @@ import {
99 renderRemoteIndex,
1010} from './utils';
1111
12import index from '../public/index.html'
13
1214/* Create new Hono app */
13const app = new Hono<{}, {}>({ strict: false });
15const app = new Hono({ strict: false });
1416
17/* Serve the index page (which contains the Swagger Docs) */
1518app.get("/", async (ctx) => {
16 console.log('ctx.env', ctx.env);
17
18 if (ctx.env?.ASSETS) {
19 let response: Response | undefined;
20 try {
21 response = await ctx.env.ASSETS.fetch(
22 ctx.request.url,
23 ctx.request.clone()
24 );
25 response =
26 response && response.status >= 200 && response.status < 400
27 ? new Response(response.body, response)
28 : undefined;
29 } catch {}
30 if (!response) {
31 return renderRemoteIndex(ctx);
32 }
19 if (index) {
20 return ctx.html(index)
3321 } else {
3422 return renderRemoteIndex(ctx);
3523 }
36
3724});
3825
39
4026/* Returns an array all service objects */
4127app.get('/services', async (c) => {
4228 return c.json(await fetchAllServices());
api/src/index.ts +1
@@ -1,3 +1,4 @@
1
12import api from './api';
23
34api.fire();
api/wrangler.toml +5 −1
@@ -2,7 +2,11 @@
22name = "awesome-privacy-api"
33compatibility_date = "2024-03-04"
44main = "src/index.ts"
5# node_compat = true
5
6rules = [
7 { type = "Text", globs = ["public/*.html"], fallthrough = true }
8]
9
610
711[site]
812bucket = "./public" # Path to your static files