Initial import of verae-middleware from zapier monorepo
This commit is contained in:
commit
fb6db30e0e
66 changed files with 6590 additions and 0 deletions
51
src/index.js
Normal file
51
src/index.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* @fileoverview Process entrypoint: HTTP listen + optional in-process poller.
|
||||
* @module index
|
||||
*/
|
||||
|
||||
import { createApp } from './app.js';
|
||||
import { config } from './config.js';
|
||||
import { createDebugger } from './debug/logger.js';
|
||||
import { startInProcessJobPoller } from './workers/inProcessJobPoller.js';
|
||||
import { connectNats, ensureStreams } from './nats/connection.js';
|
||||
import { startJobPollerWorker } from './workers/jobPollerWorker.js';
|
||||
import { startWebhookWorker } from './workers/webhookWorker.js';
|
||||
|
||||
const log = createDebugger('app');
|
||||
|
||||
/**
|
||||
* Start the HTTP server and background workers.
|
||||
* @returns {import('http').Server}
|
||||
*/
|
||||
export function startServer() {
|
||||
const app = createApp();
|
||||
|
||||
if (config.natsEnabled) {
|
||||
connectNats()
|
||||
.then(({ jsm }) => ensureStreams(jsm))
|
||||
.then(() => Promise.all([startJobPollerWorker(), startWebhookWorker()]))
|
||||
.then(() => log.info('NATS workers started'))
|
||||
.catch((err) => log.error('NATS worker start failed', { error: err.message }));
|
||||
} else {
|
||||
startInProcessJobPoller();
|
||||
}
|
||||
|
||||
const server = app.listen(config.port, config.host, () => {
|
||||
log.info('middleware listening', {
|
||||
host: config.host,
|
||||
port: config.port,
|
||||
veraeApiBaseUrl: config.veraeApiBaseUrl,
|
||||
mockVerae: config.mockVerae,
|
||||
natsEnabled: config.natsEnabled,
|
||||
});
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
`Verae Zapier middleware listening on http://${config.host}:${config.port}`,
|
||||
);
|
||||
});
|
||||
return server;
|
||||
}
|
||||
|
||||
if (process.argv[1]?.includes('index.js')) {
|
||||
startServer();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue