Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ API_PORT=3100
LOG_LEVEL=info
CURSOR_COMMIT_INTERVAL=10
POLL_INTERVAL_MS=5000
ALLOWED_ORIGINS=http://localhost:3000,https://chainlearn.io
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ const configSchema = z.object({
.positive()
.default(5000)
.describe("Polling interval in milliseconds when no new ledgers"),

allowedOrigins: z
.string()
.default("http://localhost:3000")
.transform((val) => val.split(",").map((s) => s.trim())),
});

export type Config = z.infer<typeof configSchema>;
Expand All @@ -70,6 +75,7 @@ function loadConfig(): Config {
logLevel: process.env.LOG_LEVEL,
cursorCommitInterval: process.env.CURSOR_COMMIT_INTERVAL,
pollIntervalMs: process.env.POLL_INTERVAL_MS,
allowedOrigins: process.env.ALLOWED_ORIGINS,
};

const result = configSchema.safeParse(raw);
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ async function main(): Promise<void> {
});

await app.register(cors, {
origin: true,
origin: config.allowedOrigins,
methods: ["GET"],
credentials: true,
});

await registerRoutes(app);
Expand Down
Loading