MCPcopy
hub / github.com/coder/mux / createOrpcServer

Function createOrpcServer

src/node/orpc/server.ts:740–1816  ·  view source on GitHub ↗
({
  host = "127.0.0.1",
  port = 0,
  authToken,
  context,
  serveStatic = false,
  allowHttpOrigin = false,
  // Default for non-bundled mode: from dist/node/orpc/, go up 2 levels to dist/.
  // In bundled mode (dist/runtime/), serverService computes the static dir.
  staticDir = path.join(__dirname, "../.."),
  onOrpcError = (error, options) => {
    // Auth failures are expected in browser mode while the user enters the token.
    // Avoid spamming error logs with stack traces on every unauthenticated request.
    if (error instanceof ORPCError && error.code === "UNAUTHORIZED") {
      log.debug("ORPC unauthorized request");
      return;
    }

    const formatted = formatOrpcError(error, options);
    log.error(formatted.message);

    if (log.isDebugMode()) {
      const suffix = Math.random().toString(16).slice(2);
      log.debug_obj(`orpc/${Date.now()}_${suffix}.json`, formatted.debugDump);
    }
  },
  router: existingRouter,
  desktopBridgeServer = context.desktopBridgeServer,
  browserBridgeServer = context.browserBridgeServer,
}: OrpcServerOptions)

Source from the content-addressed store, hash-verified

738 * Version: /version
739 */
740export async function createOrpcServer({
741 host = "127.0.0.1",
742 port = 0,
743 authToken,
744 context,
745 serveStatic = false,
746 allowHttpOrigin = false,
747 // Default for non-bundled mode: from dist/node/orpc/, go up 2 levels to dist/.
748 // In bundled mode (dist/runtime/), serverService computes the static dir.
749 staticDir = path.join(__dirname, "../.."),
750 onOrpcError = (error, options) => {
751 // Auth failures are expected in browser mode while the user enters the token.
752 // Avoid spamming error logs with stack traces on every unauthenticated request.
753 if (error instanceof ORPCError && error.code === "UNAUTHORIZED") {
754 log.debug("ORPC unauthorized request");
755 return;
756 }
757
758 const formatted = formatOrpcError(error, options);
759 log.error(formatted.message);
760
761 if (log.isDebugMode()) {
762 const suffix = Math.random().toString(16).slice(2);
763 log.debug_obj(`orpc/${Date.now()}_${suffix}.json`, formatted.debugDump);
764 }
765 },
766 router: existingRouter,
767 desktopBridgeServer = context.desktopBridgeServer,
768 browserBridgeServer = context.browserBridgeServer,
769}: OrpcServerOptions): Promise<OrpcServer> {
770 // Express app setup
771 const app = express();
772 app.use((req, res, next) => {
773 const requestPath = splitRequestUrlPathAndQuery(req.url);
774 if (requestPath && isValidUrlPathname(requestPath.pathname)) {
775 const { basePath, routePathname } = stripAppProxyBasePath(requestPath.pathname);
776 if (basePath) {
777 setResponsePublicBasePath(res, basePath);
778 req.url = `${routePathname}${requestPath.querySuffix}`;
779 next();
780 return;
781 }
782 }
783
784 const publicBasePath = getRequestPublicBasePath(req);
785 if (publicBasePath !== "/") {
786 setResponsePublicBasePath(res, publicBasePath);
787 }
788
789 next();
790 });
791
792 app.use((req, res, next) => {
793 if (!shouldEnforceOriginValidation(req)) {
794 next();
795 return;
796 }
797

Callers 9

createTestServerFunction · 0.90
createTestServerFunction · 0.90
startServerMethod · 0.90
createStaticTestServerFunction · 0.90
withTestOrpcServerFunction · 0.90
server.test.tsFile · 0.90
runCaseFunction · 0.90
connectToInProcessServerFunction · 0.90

Calls 15

formatOrpcErrorFunction · 0.90
stripAppProxyBasePathFunction · 0.90
escapeHtmlFunction · 0.90
routerFunction · 0.90
onErrorFunction · 0.90
attachStreamErrorHandlerFunction · 0.90
isIgnorableStreamErrorFunction · 0.90
getErrorMessageFunction · 0.90
assertFunction · 0.90
extractWsHeadersFunction · 0.90
isValidUrlPathnameFunction · 0.85

Tested by 5

createTestServerFunction · 0.72
createTestServerFunction · 0.72
createStaticTestServerFunction · 0.72
withTestOrpcServerFunction · 0.72
runCaseFunction · 0.72