Files
zeekay d3e091aa97 Serve and call every route under /v1
The resource API is /v1/rest and the operation API is /v1/rpc: named
for what they are, so neither shadows the other, and the v2-beta alias
is gone. Hanzo IAM returns to /auth/callback, the callback path IAM
already derives for this host, so sign-in needs no IAM change.

Claude-Session: https://claude.ai/code/session_01TUxvfuta1Z44KVNYuAz71F
2026-09-24 14:52:07 -07:00

59 lines
2.3 KiB
JavaScript

/**
* This is the main entry point for the server which will launch the RR7 application
* and spin up auth, api, etc.
*
* Note:
* This file will be copied to the build folder during build time.
* Running this file will not work without a build.
*/
import { serve } from '@hono/node-server';
import { serveStatic } from '@hono/node-server/serve-static';
import handle from 'hono-react-router-adapter/node';
// serveZap (WebSocket) + serveZapHttpApi (JSON-over-HTTP) both come from the
// rollup-bundled http-api module — the first-party esign ZAP server layer is
// bundled there (it's .ts workspace source that can't resolve at runtime as a
// package subpath). See rollup.config.mjs (http-api.ts is a build input).
import { serveZap, serveZapHttpApi } from './hono/server/zap/http-api.js';
import server from './hono/server/router.js';
import * as build from './index.js';
server.use(
serveStatic({
root: 'build/client',
onFound: (path, c) => {
if (path.startsWith('build/client/assets')) {
// Hard cache assets with hashed file names.
c.header('Cache-Control', 'public, immutable, max-age=31536000');
} else {
// Cache with revalidation for rest of static files.
c.header('Cache-Control', 'public, max-age=0, stale-while-revalidate=86400');
}
},
}),
);
const handler = handle(build, server);
const port = parseInt(process.env.PORT || '3000', 10);
// @hono/node-server's serve() returns the underlying Node http.Server; attach
// the ZAP-over-WebSocket RPC endpoint to it so it shares the app's port. This
// is the @zap-proto/web replacement for mounting the tRPC HTTP handler — all
// 14 routers are served over ZAP (see @hanzo/esign-trpc/zap/server/routes).
const httpServer = serve({ fetch: handler.fetch, port });
serveZap(httpServer, {
onError: (err) => console.error('[zap-rpc]', err),
});
// Serve the /v1/rpc operation API (external integrators) with the same ZAP
// service over JSON-over-HTTP. httpServe terminates only its
// declared POST routes at the http.Server level (before Hono), dispatching
// through the SAME zapRoutes + makeDispatcher + makeMintCap('apiV2'); all other
// requests (GET /v1/rpc/openapi.json, the download routes, the RR7 app) pass
// through to Hono untouched.
serveZapHttpApi(httpServer, {
onError: (err) => console.error('[zap-http-api]', err),
});