Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor worker, add hapi/handlebars #5

Merged
merged 9 commits into from
Sep 18, 2021
Merged

Refactor worker, add hapi/handlebars #5

merged 9 commits into from
Sep 18, 2021

Conversation

nchlswhttkr
Copy link
Owner

  • Add @hapi/call and @hapi/boom for better routing and error handling
  • Split off HTML snippets/responses from the main worker code into handlebars templates
  • Tidy up and document the various functions and subrequests the worker makes

Unfortunately there's still a bit of jank in getting handlebars and hapi libraries to run on Cloudflare Workers. These are mostly products of Cloudflare's custom runtime.

  • Templates need to be precompiled, since eval is disallowed
  • Some browser/Node-specific APIs (global/window/Buffer) need to be mocked with dummy values, otherwise ReferenceErrors will crop up when the worker is run

There's some jank involved with making Handlebars run on a worker, and
with loading precompiled templates. I'll document this after I finish
refactoring.

The build step is now broken out into a Node script, where it's easier
to run many commands. Given it's still Node though, it's fairly
cross-platform at least.
Some details are better obtained client-side, rather than by the worker.
Namely, the origin the worker is being served from. It's unreliable to
fetch this from headers or request data, since the value doesn't match
to the actual origin when using wrangler dev (instead of localhost, it's
the deployed URL).
[skip ci]
Once again needs some jank to make it work, will document later.
@nchlswhttkr nchlswhttkr merged commit ea3d53e into main Sep 18, 2021
@nchlswhttkr nchlswhttkr deleted the rewrite branch September 20, 2021 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant