MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / bootDebugRoutes

Function bootDebugRoutes

apps/worker/src/boot-debug.ts:80–256  ·  view source on GitHub ↗
(app: Express)

Source from the content-addressed store, hash-verified

78// Returns clickable links: an HTML page in a browser, full URLs in JSON for
79// curl. Only mounted when NODE_ENV !== 'production'.
80export function bootDebugRoutes(app: Express) {
81 app.get('/debug/cron', (req, res) => {
82 const jobs = buildJobs(req);
83 if (wantsHtml(req)) {
84 res.type('html').send(renderHtml(jobs));
85 return;
86 }
87 res.json({
88 message: 'Run a cron job now with GET or POST /debug/cron/:type',
89 jobs,
90 });
91 });
92
93 app.all('/debug/cron/:type', async (req, res) => {
94 const type = req.params.type;
95 const jobs = buildJobs(req);
96 const html = wantsHtml(req);
97
98 if (!CRON_TYPES.includes(type as CronQueueType)) {
99 const message = `Unknown cron type "${type}"`;
100 if (html) {
101 res.status(400).type('html').send(renderHtml(jobs, message));
102 return;
103 }
104 res.status(400).json({ ok: false, error: message, jobs });
105 return;
106 }
107
108 logger.info({ type }, 'Manually triggering cron job');
109
110 try {
111 const result = await cronJob({
112 data: { type: type as CronQueueType, payload: undefined },
113 } as Job<CronQueuePayload>);
114 if (html) {
115 res
116 .type('html')
117 .send(
118 renderHtml(
119 jobs,
120 `${type} ran. Result: ${JSON.stringify(result ?? null)}. Check the worker logs for details.`,
121 ),
122 );
123 return;
124 }
125 res.json({ ok: true, type, result: result ?? null });
126 } catch (error) {
127 const message = error instanceof Error ? error.message : String(error);
128 logger.error({ err: error, type }, 'Manual cron trigger failed');
129 if (html) {
130 res
131 .status(500)
132 .type('html')
133 .send(renderHtml(jobs, `Error running ${type}: ${message}`));
134 return;
135 }
136 res.status(500).json({ ok: false, type, error: message });
137 }

Callers 1

startFunction · 0.90

Calls 13

cronJobFunction · 0.90
insightsProjectJobFunction · 0.90
buildJobsFunction · 0.85
wantsHtmlFunction · 0.85
renderHtmlFunction · 0.85
infoMethod · 0.80
groupByMethod · 0.80
getMethod · 0.45
sendMethod · 0.45
stringifyMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected