-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate back to Cloudflare Workers (#147)
* Migrate back to Cloudflare Workers * Delete deprecated CF pages files
- Loading branch information
1 parent
7c28341
commit e2d5578
Showing
6 changed files
with
45 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { ExportedHandler } from "@cloudflare/workers-types"; | ||
import { createRequestHandler, type ServerBuild } from "react-router"; | ||
|
||
import { getLoadContext } from "~/load-context"; | ||
|
||
import * as build from "../build/server"; | ||
|
||
const requestHandler = createRequestHandler(build as unknown as ServerBuild); | ||
|
||
export default { | ||
// @ts-expect-error TODO figure out types here | ||
async fetch(request: any, env: any, ctx: any) { | ||
try { | ||
const loadContext = getLoadContext({ | ||
request, | ||
context: { | ||
cloudflare: { | ||
ctx: { | ||
waitUntil: ctx.waitUntil.bind(ctx), | ||
passThroughOnException: | ||
ctx.passThroughOnException.bind(ctx), | ||
}, | ||
cf: request.cf as never, | ||
// @ts-expect-error TODO: figure out how to get this type to work | ||
caches, | ||
env, | ||
}, | ||
}, | ||
}); | ||
return await requestHandler(request, loadContext); | ||
} catch (error) { | ||
console.log(error); | ||
return new Response("An unexpected error occurred", { | ||
status: 500, | ||
}); | ||
} | ||
}, | ||
} satisfies ExportedHandler<Env>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
# default deploy name | ||
name = "counterscale" | ||
pages_build_output_dir = "build/client" | ||
main = "./workers/app.ts" | ||
|
||
# https://developers.cloudflare.com/workers/platform/compatibility-dates | ||
compatibility_date = "2024-12-13" | ||
|
||
assets = { directory = "build/client" } | ||
|
||
[[analytics_engine_datasets]] | ||
binding = "WEB_COUNTER_AE" | ||
dataset = "metricsDataset" |