mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 14:45:24 +00:00
feat: serve plugin http and websockets from one mount instead of ports
This commit is contained in:
1 parent
c496a093ca
commit
8431570ff7
102 files changed
+2894
-2308
No files matched your search
@@ -6,10 +6,14 @@ import {
|
||||
} from "./scheduler.js";
|
||||
|
||||
export async function activate(ctx: PluginContext) {
|
||||
startAutomationsService();
|
||||
startAutomationsService(
|
||||
// The webhook route authenticates on its own per-automation token rather
|
||||
// than a session, which is the point of an inbound webhook.
|
||||
ctx.http.router({ public: ["/webhook/:token"] }),
|
||||
);
|
||||
startAutomationScheduler();
|
||||
ctx.log.info(
|
||||
"Automations router registered at /automations; scheduler started",
|
||||
"Automations routes mounted at /plugin-api/automations; scheduler started",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import crypto from "node:crypto";
|
||||
import express, { type Request, type Response } from "express";
|
||||
import express, { type Request, type Response, type Router } from "express";
|
||||
import type { AuthenticatedRequest } from "../../../../src/types/index.js";
|
||||
import type {
|
||||
AutomationDefinition,
|
||||
@@ -19,10 +19,6 @@ import { createCurrentAutomationRepository } from "../../../../src/backend/datab
|
||||
import type { AutomationRow } from "../../../../src/backend/database/repositories/automation-repository.js";
|
||||
import { AutomationEngine } from "./engine.js";
|
||||
import { computeNextDueAt, isValidCron, isValidTimezone } from "./cron.js";
|
||||
import {
|
||||
registerAutomationsRouter,
|
||||
unregisterAutomationsRouter,
|
||||
} from "../../../../src/backend/database/routes/automation-dispatch.js";
|
||||
|
||||
export const router = express.Router();
|
||||
|
||||
@@ -821,12 +817,12 @@ function timingSafeEqual(a: string, b: string): boolean {
|
||||
|
||||
/** Called from activate(). Mounts this router at /automations via the shared
|
||||
* dispatcher. */
|
||||
export function startAutomationsService(): void {
|
||||
registerAutomationsRouter(router);
|
||||
export function startAutomationsService(mountOn: Router): void {
|
||||
mountOn.use(router);
|
||||
}
|
||||
|
||||
/** Called from deactivate(). /automations/* falls back to 404 until
|
||||
* reactivated. */
|
||||
export function stopAutomationsService(): void {
|
||||
unregisterAutomationsRouter();
|
||||
// Unmounted by the runtime when the plugin deactivates.
|
||||
}
|
||||
@@ -75,7 +75,7 @@ export interface AutomationInput {
|
||||
|
||||
export async function listAutomations(): Promise<AutomationRow[]> {
|
||||
try {
|
||||
return (await authApi.get("/automations")).data;
|
||||
return (await authApi.get("/plugin-api/automations")).data;
|
||||
} catch (error) {
|
||||
throw handleApiError(error, "fetch automations");
|
||||
}
|
||||
@@ -85,7 +85,7 @@ export async function createAutomation(
|
||||
input: AutomationInput,
|
||||
): Promise<AutomationRow> {
|
||||
try {
|
||||
return (await authApi.post("/automations", input)).data;
|
||||
return (await authApi.post("/plugin-api/automations", input)).data;
|
||||
} catch (error) {
|
||||
throw handleApiError(error, "create automation");
|
||||
}
|
||||
@@ -96,7 +96,7 @@ export async function updateAutomation(
|
||||
input: Partial<AutomationInput>,
|
||||
): Promise<AutomationRow> {
|
||||
try {
|
||||
return (await authApi.put(`/automations/${id}`, input)).data;
|
||||
return (await authApi.put(`/plugin-api/automations/${id}`, input)).data;
|
||||
} catch (error) {
|
||||
throw handleApiError(error, "update automation");
|
||||
}
|
||||
@@ -104,7 +104,7 @@ export async function updateAutomation(
|
||||
|
||||
export async function deleteAutomation(id: number): Promise<void> {
|
||||
try {
|
||||
await authApi.delete(`/automations/${id}`);
|
||||
await authApi.delete(`/plugin-api/automations/${id}`);
|
||||
} catch (error) {
|
||||
throw handleApiError(error, "delete automation");
|
||||
}
|
||||
@@ -115,7 +115,8 @@ export async function runAutomation(
|
||||
options: { dryRun?: boolean } = {},
|
||||
): Promise<AutomationRunOutcome> {
|
||||
try {
|
||||
return (await authApi.post(`/automations/${id}/run`, options)).data;
|
||||
return (await authApi.post(`/plugin-api/automations/${id}/run`, options))
|
||||
.data;
|
||||
} catch (error) {
|
||||
throw handleApiError(error, "run automation");
|
||||
}
|
||||
@@ -125,8 +126,11 @@ export async function listAutomationRuns(
|
||||
options: { automationId?: number; limit?: number; offset?: number } = {},
|
||||
): Promise<AutomationRunRow[]> {
|
||||
try {
|
||||
return (await authApi.get("/automations/runs/history", { params: options }))
|
||||
.data;
|
||||
return (
|
||||
await authApi.get("/plugin-api/automations/runs/history", {
|
||||
params: options,
|
||||
})
|
||||
).data;
|
||||
} catch (error) {
|
||||
throw handleApiError(error, "fetch automation runs");
|
||||
}
|
||||
@@ -136,7 +140,8 @@ export async function listAutomationRunSteps(
|
||||
runId: number,
|
||||
): Promise<AutomationRunStepRow[]> {
|
||||
try {
|
||||
return (await authApi.get(`/automations/runs/${runId}/steps`)).data;
|
||||
return (await authApi.get(`/plugin-api/automations/runs/${runId}/steps`))
|
||||
.data;
|
||||
} catch (error) {
|
||||
throw handleApiError(error, "fetch run steps");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user