Skip to content

Firebase / Google Cloud Functions Support #958

@joshjacks

Description

@joshjacks

Describe the feature

Firebase functions (v2) provide an onRequest function which is a thin wrapper around an Express endpoint. Unfortunately, the wrapper appears to consume the request before it hits user space and so it is incompatible with the oRPC Express adapter.

Example of Ideal (an example of what works with tRPC):

export const api = onRequest((req, res) => {
    req.url = req.url.replace("/api", "");
    return createHTTPHandler({
        router: appRouter,
        createContext,
    })(req, res);
});

What the docs currently suggest:

import { RPCHandler } from "@orpc/server/node";
import { onRequest } from "firebase-functions/v2/https";
import { createContext } from "./context.js";
import { router } from "./router.js";

const handler = new RPCHandler(router);

export const api = onRequest(async (req, res) => {
    await handler.handle(req, res, {
        prefix: "/api",
        context: await createContext(req),
    });
});

However, with this suggestion, the input is always undefined, though the route is matched correctly and no error is thrown (except for a validation error on the input if one exists of course).

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions