forked from kriasoft/react-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
43 lines (38 loc) · 1 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* SPDX-FileCopyrightText: 2014-present Kriasoft */
/* SPDX-License-Identifier: MIT */
import {
getAssetFromKV,
serveSinglePageApp,
} from "@cloudflare/kv-asset-handler";
import { Hono } from "hono";
import manifest from "__STATIC_CONTENT_MANIFEST";
/**
* Application router for Cloudflare Workers
* @see https://honojs.dev/
*/
const app = new Hono();
app.get("/echo", (ctx) => {
return ctx.json({
headers: Object.fromEntries(ctx.req.headers.entries()),
cf: ctx.req.cf,
});
});
// Serve web application assets bundled into
// the worker script from the `dist/app` folder
// https://github.com/cloudflare/kv-asset-handler#readme
app.get("*", async ({ req, executionCtx, env }) => {
return await getAssetFromKV(
{
request: req,
waitUntil(promise) {
return executionCtx.waitUntil(promise);
},
},
{
ASSET_NAMESPACE: env.__STATIC_CONTENT,
ASSET_MANIFEST: JSON.parse(manifest),
mapRequestToAsset: serveSinglePageApp,
}
);
});
export default app;