Updates API landing for Hono on CF workers for Swagger

This commit is contained in:
Alicia Sykes 2024-03-08 18:09:16 +00:00
parent 3e2d719d47
commit 40611ea022
3 changed files with 12 additions and 21 deletions

View file

@ -9,34 +9,20 @@ import {
renderRemoteIndex,
} from './utils';
import index from '../public/index.html'
/* Create new Hono app */
const app = new Hono<{}, {}>({ strict: false });
const app = new Hono({ strict: false });
/* Serve the index page (which contains the Swagger Docs) */
app.get("/", async (ctx) => {
console.log('ctx.env', ctx.env);
if (ctx.env?.ASSETS) {
let response: Response | undefined;
try {
response = await ctx.env.ASSETS.fetch(
ctx.request.url,
ctx.request.clone()
);
response =
response && response.status >= 200 && response.status < 400
? new Response(response.body, response)
: undefined;
} catch {}
if (!response) {
return renderRemoteIndex(ctx);
}
if (index) {
return ctx.html(index)
} else {
return renderRemoteIndex(ctx);
}
});
/* Returns an array all service objects */
app.get('/services', async (c) => {
return c.json(await fetchAllServices());

View file

@ -1,3 +1,4 @@
import api from './api';
api.fire();

View file

@ -2,7 +2,11 @@
name = "awesome-privacy-api"
compatibility_date = "2024-03-04"
main = "src/index.ts"
# node_compat = true
rules = [
{ type = "Text", globs = ["public/*.html"], fallthrough = true }
]
[site]
bucket = "./public" # Path to your static files