Skip to content

feat: add http-gateway library and cloudflare gateway example project #42

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

nathanosdev
Copy link
Member

@nathanosdev nathanosdev commented Feb 19, 2025

This PR includes a very minimal version of a JavaScript based HTTP Gateway library and an example project that shows how to use this library to run an HTTP Gateway on Cloudflare. This is still experimental and a PoC at this point.

@nathanosdev nathanosdev requested a review from a team as a code owner February 19, 2025 15:04
@@ -5,6 +5,7 @@ dist/
pocket-ic
.env
Cargo.lock
.wrangler
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This folder is generated by Cloudflare's wrangler CLI

README.md Outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated cleanup, removing deprecated projects and replacing with newer ones.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next few files belong to the Cloudflare worker example project that leverages the JS library to run an HTTP Gateway. Docs and implementation are still a little rough around the edges.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main logic for the Cloudlfare worker.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next few files belong to a library that exports a simple wrapper around an actor built with pre-generated types that correspond to the expected interface for a canister that the HTTP Gateway will interact with. There is also some simple mapping between more idiomatic TypeScript types and those generated by Candid.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next few files belong to the actual HTTP Gateway JavaScript library.

@@ -0,0 +1,40 @@
import { HttpGatewayClient } from '@dfinity/http-gateway';
import { HttpAgent } from '@dfinity/agent';
import RESPONSE_VERIFICATION_WASM from '@dfinity/response-verification/dist/web/web_bg.wasm';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had issues with loading the WASM when the HTTP Gateway library did it internally. This should work fine in other environments, but Cloudflare doesn't like it for some reason. Loading it explicitly inside the worker and passing it as a parameter works well, although I really don't like it.

Copy link
Member

@ilbertt ilbertt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-approving, with some minor comments

@nathanosdev nathanosdev force-pushed the nathan/add-http-gateway-library branch from 57a261e to 4fcd03f Compare May 7, 2025 13:57
@nathanosdev nathanosdev requested a review from ilbertt May 7, 2025 16:10
Copy link
Contributor

@przydatek przydatek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the example be built/tested by CI? (sorry if this is a stupid question, I'm somewhat lost in the JS-code 😕 😉) If not, would it make sense to add some simple test, just to make sure that it is in a healthy state when e.g. some of the dependencies get upgraded?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file empty on purpose?

@@ -0,0 +1,19 @@
# Cloudflare Worker based ICP HTTP Gateway
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it seems to me "based" should be preceded with a hyphen, but am not sure whether it should be "Cloudflare-Worker-based" or "Cloudflare Worker-based" (and obviously I'm not a native speaker 😢 ). Maybe the best solution would be to reformulate to "An ICP HTTP Gateway based on a Cloudflare Worker"?

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.

3 participants