diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts
index 980fff6..fe1275b 100644
--- a/packages/backend/src/index.ts
+++ b/packages/backend/src/index.ts
@@ -7,6 +7,8 @@ const processedRequests = new Set();
let lastRequestId: string | null = null;
// Store the cursor from the last query for pagination
let lastCursor: string | null = null;
+// Store the interval ID for polling
+let pollingIntervalId: ReturnType | null = null;
// Simple URL parser function to extract host and path
function parseUrl(sdk: SDK, url: string): { host: string, path: string } {
@@ -305,13 +307,45 @@ async function checkRequest(sdk: SDK, requestId: string): Promise {
// Function to start the periodic polling
async function startPolling(sdk: SDK): Promise {
+ // Only start polling if it's not already running
+ if (pollingIntervalId !== null) {
+ sdk.console.log(`[MethodCheck] Polling already active, not starting again`);
+ return;
+ }
+
// Poll immediately, then every 5 seconds
await pollForRequests(sdk);
// Continue polling at regular intervals
- setInterval(async () => {
+ pollingIntervalId = setInterval(async () => {
await pollForRequests(sdk);
}, 5000);
+
+ sdk.console.log(`[MethodCheck] Polling started with interval ID: ${pollingIntervalId}`);
+}
+
+// Function to stop the periodic polling
+function stopPolling(sdk: SDK): boolean {
+ if (pollingIntervalId === null) {
+ sdk.console.log(`[MethodCheck] No active polling to stop`);
+ return false;
+ }
+
+ clearInterval(pollingIntervalId);
+ pollingIntervalId = null;
+ sdk.console.log(`[MethodCheck] Polling stopped`);
+ return true;
+}
+
+// Function to toggle polling state
+function togglePolling(sdk: SDK): boolean {
+ if (pollingIntervalId === null) {
+ startPolling(sdk);
+ return true; // Polling is now active
+ } else {
+ stopPolling(sdk);
+ return false; // Polling is now inactive
+ }
}
// Function to create a test finding
@@ -355,12 +389,16 @@ If you see this, it means the findings API is working correctly!`,
// Export the API type
export type API = DefineAPI<{
checkRequest: typeof checkRequest;
+ togglePolling: typeof togglePolling;
+ isPollingActive: () => boolean;
}>;
// Initialize the plugin
export function init(sdk: SDK) {
// Register the API
sdk.api.register("checkRequest", checkRequest);
+ sdk.api.register("togglePolling", () => togglePolling(sdk));
+ sdk.api.register("isPollingActive", () => pollingIntervalId !== null);
// Listen for proxy responses
try {
diff --git a/packages/frontend/src/hooks/useCaidoSDK.ts b/packages/frontend/src/hooks/useCaidoSDK.ts
new file mode 100644
index 0000000..3a00836
--- /dev/null
+++ b/packages/frontend/src/hooks/useCaidoSDK.ts
@@ -0,0 +1,6 @@
+import { inject } from 'vue';
+import type { CaidoSDK } from '../index';
+
+export function useCaidoSDK(): CaidoSDK | null {
+ return inject('sdk') || null;
+}
diff --git a/packages/frontend/src/views/App.vue b/packages/frontend/src/views/App.vue
index 52da974..821da6a 100644
--- a/packages/frontend/src/views/App.vue
+++ b/packages/frontend/src/views/App.vue
@@ -29,9 +29,47 @@
History and selecting Check Available Methods.
+
+
+
+ This plugin checks for alternative HTTP methods that are allowed on
+ endpoints.
+
+
+
Polling is active
+
Polling is inactive
+