-
-
Notifications
You must be signed in to change notification settings - Fork 75
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Basically for "proxy" style use cases. We're trying out https://electric-sql.com and would love to leverage all the existing middleware, logging setup, tracing, etc we've got with oRPC, in proxy scenarios.
Here's an (imperfect but demonstrative) example for electric:
const sync = base.
// re-use our existing orpc middlewares, logging, etc
.use(requireAuth)
// expose a plain http endpoint for electric
.route({
method: 'GET',
path: '/api/sync/threads',
})
// electric's standard search params
.input(z.object({
live: z.string().optional(),
handle: z.string().optional(),
offset: z.string().optional(),
cursor: z.string().optional(),
}))
// proxy the electric sync requests to electric backend
.handler(async ({ context, input, errors }) => {
// .. set input params on the url of course.. skipping in this example
const electricUrl = new URL('http://localhost:4028/v1/shape');
electricUrl.searchParams.set('table', 'threads');
// access orpc context as needed...
// const xyz = context.db.get(foo)
// proxy the request
const response = await fetch(electricUrl, {
cf: { cacheEverything: true },
});
if (!response.ok) {
throw errors.INTERNAL_SERVER_ERROR({ message: `Sync error: ${response.statusText}` });
}
return response;
});
And then use it like so on the client:
const stream = new ShapeStream({
url: `http://{server w orpc}/api/threads/sync`,
})
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request