-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store-indexer): separate postgres indexer/frontend services (#1887)
- Loading branch information
Showing
9 changed files
with
171 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@latticexyz/store-indexer": major | ||
--- | ||
|
||
Separated frontend server and indexer service for Postgres indexer. Now you can run the Postgres indexer with one writer and many readers. | ||
|
||
If you were previously using the `postgres-indexer` binary, you'll now need to run both `postgres-indexer` and `postgres-frontend`. | ||
|
||
For consistency, the Postgres database logs are now disabled by default. If you were using these, please let us know so we can add them back in with an environment variable flag. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env node | ||
import "dotenv/config"; | ||
import { z } from "zod"; | ||
import fastify from "fastify"; | ||
import { fastifyTRPCPlugin } from "@trpc/server/adapters/fastify"; | ||
import { AppRouter, createAppRouter } from "@latticexyz/store-sync/trpc-indexer"; | ||
import { createQueryAdapter } from "../src/postgres/createQueryAdapter"; | ||
import { drizzle } from "drizzle-orm/postgres-js"; | ||
import postgres from "postgres"; | ||
import { frontendEnvSchema, parseEnv } from "./parseEnv"; | ||
|
||
const env = parseEnv( | ||
z.intersection( | ||
frontendEnvSchema, | ||
z.object({ | ||
DATABASE_URL: z.string(), | ||
}) | ||
) | ||
); | ||
|
||
const database = drizzle(postgres(env.DATABASE_URL)); | ||
|
||
// @see https://fastify.dev/docs/latest/ | ||
const server = fastify({ | ||
maxParamLength: 5000, | ||
}); | ||
|
||
await server.register(import("@fastify/cors")); | ||
|
||
// k8s healthchecks | ||
server.get("/healthz", (req, res) => res.code(200).send()); | ||
server.get("/readyz", (req, res) => res.code(200).send()); | ||
|
||
// @see https://trpc.io/docs/server/adapters/fastify | ||
server.register(fastifyTRPCPlugin<AppRouter>, { | ||
prefix: "/trpc", | ||
trpcOptions: { | ||
router: createAppRouter(), | ||
createContext: async () => ({ | ||
queryAdapter: await createQueryAdapter(database), | ||
}), | ||
}, | ||
}); | ||
|
||
await server.listen({ host: env.HOST, port: env.PORT }); | ||
console.log(`postgres indexer frontend listening on http://${env.HOST}:${env.PORT}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.