detached 28802ca

fix: cloudflare workers compatible initialization

commit
28802cad3407b3e561325d6f0fc7700e9630e6f0
author
bnema · · 2026-01-18 21:18 UTC
parent
84b7c36
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +14 -7
M src/hooks.server.ts +14 -7
@@ -33,20 +33,27 @@ async function setAllUsersOffline() {
3333 }
3434 }
3535
36-// Initialize server
37-Promise.resolve()
38- .then(async () => {
36+// Initialize server (deferred, non-blocking for Cloudflare Workers compatibility)
37+let initialized = false;
38+async function initializeServer() {
39+ if (initialized) return;
40+ initialized = true;
41+ try {
3942 log.info('Initializing server...');
4043 await ensureDefaultChatRoom();
4144 await setAllUsersOffline();
4245 log.info('Server initialized successfully');
43- })
44- .catch((error: unknown) => {
46+ } catch (error: unknown) {
4547 log.error('Failed to initialize server:', { error });
46- process.exit(1);
47- });
48+ // Don't exit - let the server continue and retry on next request
49+ initialized = false;
50+ }
51+}
4852
4953 export const handle: Handle = async ({ event, resolve }) => {
54+ // Lazy initialization on first request (Cloudflare Workers compatible)
55+ await initializeServer();
56+
5057 log.debug('Handling request', { path: event.url.pathname });
5158
5259 // CSRF protection: validate Origin header for state-changing requests
@@ -33,20 +33,27 @@ async function setAllUsersOffline() {
33 }33 }
34 }34 }
35 35
36-// Initialize server36+// Initialize server (deferred, non-blocking for Cloudflare Workers compatibility)
37-Promise.resolve()37+let initialized = false;
38- .then(async () => {38+async function initializeServer() {
39+ if (initialized) return;
40+ initialized = true;
41+ try {
39 log.info('Initializing server...');42 log.info('Initializing server...');
40 await ensureDefaultChatRoom();43 await ensureDefaultChatRoom();
41 await setAllUsersOffline();44 await setAllUsersOffline();
42 log.info('Server initialized successfully');45 log.info('Server initialized successfully');
43- })46+ } catch (error: unknown) {
44- .catch((error: unknown) => {
45 log.error('Failed to initialize server:', { error });47 log.error('Failed to initialize server:', { error });
46- process.exit(1);48+ // Don't exit - let the server continue and retry on next request
47- });49+ initialized = false;
50+ }
51+}
48 52
49 export const handle: Handle = async ({ event, resolve }) => {53 export const handle: Handle = async ({ event, resolve }) => {
54+ // Lazy initialization on first request (Cloudflare Workers compatible)
55+ await initializeServer();
56+
50 log.debug('Handling request', { path: event.url.pathname });57 log.debug('Handling request', { path: event.url.pathname });
51 58
52 // CSRF protection: validate Origin header for state-changing requests59 // CSRF protection: validate Origin header for state-changing requests

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 9

↑↓ moveenter openesc close