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

Add CTX.do Service Binding #6

Open
Tracked by #1
nathanclevenger opened this issue Oct 26, 2022 · 0 comments
Open
Tracked by #1

Add CTX.do Service Binding #6

nathanclevenger opened this issue Oct 26, 2022 · 0 comments
Assignees

Comments

@nathanclevenger
Copy link
Member

Now that the service is deploying to the drivly Cloudflare account, you can use the CTX.do service binding.

We should add this to the wrangler.toml:

services = [
  { binding = "CTX", service = "ctx-do", environment = "production" }
]

And then replace:

const { hostname, pathname, search } = new URL(req.url)

with:

const { user, hostname, pathname, rootPath, pathSegments, query } = await env.CTX.fetch(req).then(res => res.json())

This give us JWT and APIKey auth support, as well as a ton of convenience methods like query is search into an object, and body is also cloned and either string or array or object based on the contents of the request body, if there is one. Path segments is also a great convenience as it's an array of pathname split on '/' so params can be easily destructured

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

No branches or pull requests

2 participants