Initial import of verae-middleware from zapier monorepo
This commit is contained in:
commit
7fe9f616fa
66 changed files with 6590 additions and 0 deletions
55
src/app.js
Normal file
55
src/app.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* @fileoverview Express application factory for the Zapier-facing HTTP edge.
|
||||
* @module app
|
||||
*/
|
||||
|
||||
import express from 'express';
|
||||
import { sendError } from './errors.js';
|
||||
import { createDebugger } from './debug/logger.js';
|
||||
import { traceMiddleware } from './debug/trace.js';
|
||||
import { apiRoutes } from './routes/index.js';
|
||||
import { loadStore } from './store/db.js';
|
||||
import { config } from './config.js';
|
||||
import { isNatsConnected } from './nats/connection.js';
|
||||
|
||||
const log = createDebugger('app');
|
||||
|
||||
/**
|
||||
* Create the Express app (does not listen).
|
||||
*
|
||||
* @param {{ load?: boolean }} [options]
|
||||
* @returns {import('express').Express}
|
||||
*/
|
||||
export function createApp(options = {}) {
|
||||
if (options.load !== false) {
|
||||
loadStore();
|
||||
}
|
||||
|
||||
const app = express();
|
||||
app.disable('x-powered-by');
|
||||
|
||||
app.use(express.json({ limit: '12mb' }));
|
||||
app.use(traceMiddleware);
|
||||
|
||||
/**
|
||||
* Liveness probe.
|
||||
*/
|
||||
app.get('/health', (_req, res) => {
|
||||
res.json({
|
||||
status: 'ok',
|
||||
service: 'verae-zapier-middleware',
|
||||
mockVerae: config.mockVerae,
|
||||
natsEnabled: config.natsEnabled,
|
||||
natsConnected: isNatsConnected(),
|
||||
});
|
||||
});
|
||||
|
||||
app.use('/zapier', apiRoutes);
|
||||
|
||||
app.use((err, _req, res, _next) => {
|
||||
sendError(res, err);
|
||||
});
|
||||
|
||||
log.info('express app created');
|
||||
return app;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue