|
1 | | -#!/usr/bin/env node |
2 | | - |
3 | | -import source from '@stripe/sync-source-stripe' |
4 | | -import pgDestination from '@stripe/sync-destination-postgres' |
5 | | -import sheetsDestination from '@stripe/sync-destination-google-sheets' |
6 | | -import { createConnectorResolver } from '../lib/index.js' |
7 | | -import { createApp } from './app.js' |
8 | | -import { logger } from '../logger.js' |
9 | | -import { ENGINE_SERVER_OPTIONS } from '../http-server-options.js' |
10 | | - |
11 | | -const port = Number(process.env.PORT || 3001) |
12 | | - |
13 | | -async function main() { |
14 | | - if (process.env.DANGEROUSLY_VERBOSE_LOGGING === 'true') { |
15 | | - logger.warn( |
16 | | - '⚠️ DANGEROUSLY_VERBOSE_LOGGING is enabled — all request headers and message payloads will be logged. Do not use in production.' |
17 | | - ) |
18 | | - } |
19 | | - |
20 | | - const resolver = await createConnectorResolver({ |
21 | | - sources: { stripe: source }, |
22 | | - destinations: { postgres: pgDestination, google_sheets: sheetsDestination }, |
23 | | - }) |
24 | | - const app = await createApp(resolver) |
25 | | - |
26 | | - // Use the web-standard fetch handler with the runtime's native server. |
27 | | - // Bun.serve() properly cancels ReadableStreams on client disconnect; |
28 | | - // @hono/node-server is the fallback for Node.js / tsx. |
29 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
30 | | - if (typeof (globalThis as any).Bun !== 'undefined') { |
31 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
32 | | - ;(globalThis as any).Bun.serve({ fetch: app.fetch, port, idleTimeout: 60 }) |
33 | | - logger.warn( |
34 | | - { port, server: 'Bun.serve' }, |
35 | | - `Sync Engine API listening on http://localhost:${port}` |
36 | | - ) |
37 | | - } else { |
38 | | - const { serve } = await import('@hono/node-server') |
39 | | - serve( |
40 | | - { |
41 | | - fetch: app.fetch, |
42 | | - port, |
43 | | - serverOptions: ENGINE_SERVER_OPTIONS, |
44 | | - }, |
45 | | - (info) => { |
46 | | - logger.info( |
47 | | - { port: info.port }, |
48 | | - `Sync Engine API listening on http://localhost:${info.port}` |
49 | | - ) |
50 | | - } |
51 | | - ) |
52 | | - } |
53 | | -} |
54 | | - |
55 | | -main() |
| 1 | +export { createApp } from './app.js' |
| 2 | +export { startApiServer } from './server.js' |
| 3 | +export type { StartApiServerOptions } from './server.js' |
0 commit comments