Update to latest wrangler version
Change-Id: I213f3e6bfd5dd6cd2479ae4d4ce4ee2a94f228a2
Reviewed-on: https://src.jottocraft.com/c/dtps/+/140
Reviewed-by: spike <[email protected]>
diff --git a/server/index.js b/server/index.js
index db20a67..6a653c4 100644
--- a/server/index.js
+++ b/server/index.js
@@ -3,12 +3,8 @@
* Copyright (c) jottocraft 2022
*/
-import { getAssetFromKV, NotFoundError, MethodNotAllowedError } from '@cloudflare/kv-asset-handler';
-import manifestJSON from '__STATIC_CONTENT_MANIFEST';
import UAParser from "ua-parser-js";
-const assetManifest = JSON.parse(manifestJSON);
-
async function logAnalyticsEvent(url, request, env, ctx) {
//Collect statistics about this event
const entrypoint = url.pathname.split("/").pop();
@@ -35,21 +31,18 @@
});
}
-async function serveKV(request, env, ctx) {
+async function serveStaticSite(request, env, ctx) {
const url = new URL(request.url);
- try {
- const res = await getAssetFromKV(
- {
- request,
- waitUntil: (promise) => ctx.waitUntil(promise)
- },
- {
- ASSET_NAMESPACE: env.__STATIC_CONTENT,
- ASSET_MANIFEST: assetManifest
- }
- );
+ const assetResponse = await env.ASSETS.fetch(request);
+ if (assetResponse.status === 404) {
+ return env.HTTP_STATUS_PAGES.fetch("https://http-status-pages.jottocraft.com/?status=404&brand=dtps");
+ } else if (assetResponse.status === 405) {
+ return env.HTTP_STATUS_PAGES.fetch("https://http-status-pages.jottocraft.com/?status=405&brand=dtps");
+ } else if (assetResponse.status >= 500) {
+ return env.HTTP_STATUS_PAGES.fetch("https://http-status-pages.jottocraft.com/?status=" + assetResponse.status + "&brand=dtps");
+ } else {
ctx.waitUntil((async function () {
//Log analytics event
if (
@@ -63,20 +56,12 @@
}
})());
- return res;
- } catch (e) {
- if (e instanceof NotFoundError) {
- return env.HTTP_STATUS_PAGES.fetch("https://http-status-pages.jottocraft.com/?status=404&brand=dtps");
- } else if (e instanceof MethodNotAllowedError) {
- return env.HTTP_STATUS_PAGES.fetch("https://http-status-pages.jottocraft.com/?status=405&brand=dtps");
- } else {
- return env.HTTP_STATUS_PAGES.fetch("https://http-status-pages.jottocraft.com/?status=500&brand=dtps");
- }
+ return assetResponse;
}
}
export default {
async fetch(request, env, ctx) {
- return await serveKV(request, env, ctx);
+ return await serveStaticSite(request, env, ctx);
}
};