Skip to content

Commit bb13115

Browse files
committed
CF Functions
1 parent 9b7ad14 commit bb13115

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

apps/tutorial/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/node_modules/
1010

1111
# misc
12+
.wrangler/
1213
/.env*
1314
/.pnp*
1415
/.sass-cache

apps/tutorial/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"lint": "pnpm -w exec lint",
1616
"lint:types": "glint",
1717
"lint:fix": "pnpm -w exec lint fix",
18+
"cf": "cd dist && npx wrangler pages dev ./",
1819
"start": "concurrently 'ember serve' 'pnpm _syncPnpm --watch' --names 'serve,sync deps'",
1920
"test:ember": "ember test --test-port 0",
2021
"_syncPnpm": "pnpm sync-dependencies-meta-injected",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import fs from 'node:fs/promises';
2+
3+
export async function onRequest(context) {
4+
try {
5+
return errorIfNotFound(context);
6+
} catch (err) {
7+
return new Response(`${err.message}\n${err.stack}`, { status: 500 });
8+
}
9+
}
10+
11+
function errorIfNotFound(context) {
12+
const { request, next } = context;
13+
const url = new URL(request.url);
14+
15+
/**
16+
* If the extension ends with gjs
17+
* or md, we check disk.
18+
* otherwise we fallback to default behavior.
19+
*/
20+
let isGJS = url.pathname.endsWith('.gjs');
21+
let isGTS = url.pathname.endsWith('.gts');
22+
let isMD = url.pathname.endsWith('.md');
23+
24+
let shouldCheck = isGJS || isGTS || isMD;
25+
26+
if (!shouldCheck) {
27+
// let Cloudflare do its thing
28+
return await next();
29+
}
30+
31+
32+
}

0 commit comments

Comments
 (0)