Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const processedRequests = new Set<string>();
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<typeof setInterval> | null = null;

// Simple URL parser function to extract host and path
function parseUrl(sdk: SDK, url: string): { host: string, path: string } {
Expand Down Expand Up @@ -305,13 +307,45 @@ async function checkRequest(sdk: SDK, requestId: string): Promise<string> {

// Function to start the periodic polling
async function startPolling(sdk: SDK): Promise<void> {
// 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
Expand Down Expand Up @@ -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<API>) {
// 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 {
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/src/hooks/useCaidoSDK.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { inject } from 'vue';
import type { CaidoSDK } from '../index';

export function useCaidoSDK(): CaidoSDK | null {
return inject<CaidoSDK>('sdk') || null;
}
40 changes: 39 additions & 1 deletion packages/frontend/src/views/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,47 @@
History and selecting <strong>Check Available Methods</strong>.
</p>
</div>

<div class="mb-4">
<p class="mb-2">
This plugin checks for alternative HTTP methods that are allowed on
endpoints.
</p>
<button
class="px-4 py-2 rounded"
:class="
pollingActive
? 'bg-red-500 hover:bg-red-600'
: 'bg-green-500 hover:bg-green-600'
"
@click="togglePolling"
>
{{ pollingActive ? "Disable Polling" : "Enable Polling" }}
</button>
<span class="ml-2 text-sm" v-if="pollingActive">Polling is active</span>
<span class="ml-2 text-sm" v-else>Polling is inactive</span>
</div>
</div>
</template>

<script setup lang="ts">
// No additional script needed for this simple informational view
import { ref, onMounted } from "vue";
import { useCaidoSDK } from "../hooks/useCaidoSDK";

const sdk = useCaidoSDK();
const pollingActive = ref(false);

// Check initial polling state
onMounted(async () => {
if (sdk) {
pollingActive.value = await sdk.api.isPollingActive();
}
});

// Toggle polling function
const togglePolling = async () => {
if (sdk) {
pollingActive.value = await sdk.api.togglePolling();
}
};
</script>
Loading