From 4009414529f32770cb61defc4beb7f527acc3e45 Mon Sep 17 00:00:00 2001 From: Pol Avec Date: Tue, 20 May 2025 11:09:09 -0400 Subject: [PATCH] Add debug page for testing x402 endpoints --- cmd/server/static/js/debug.js | 24 ++++++++++++++++++ cmd/server/templates/debug.html | 43 +++++++++++++++++++++++++++++++++ ui/handler.go | 8 ++++++ 3 files changed, 75 insertions(+) create mode 100644 cmd/server/static/js/debug.js create mode 100644 cmd/server/templates/debug.html diff --git a/cmd/server/static/js/debug.js b/cmd/server/static/js/debug.js new file mode 100644 index 0000000..64730f7 --- /dev/null +++ b/cmd/server/static/js/debug.js @@ -0,0 +1,24 @@ +document.addEventListener('DOMContentLoaded', function () { + const form = document.getElementById('debug-form'); + const output = document.getElementById('response-output'); + form.addEventListener('submit', async function (e) { + e.preventDefault(); + const url = document.getElementById('target-url').value; + const method = document.getElementById('method-select').value; + const payment = document.getElementById('payment-header').value.trim(); + output.textContent = 'Loading...'; + try { + const headers = {}; + if (payment) headers['X-Payment'] = payment; + const res = await fetch(url, { method: method, headers: headers }); + const text = await res.text(); + try { + output.textContent = JSON.stringify(JSON.parse(text), null, 2); + } catch { + output.textContent = text; + } + } catch (err) { + output.textContent = 'Request failed: ' + err; + } + }); +}); diff --git a/cmd/server/templates/debug.html b/cmd/server/templates/debug.html new file mode 100644 index 0000000..3e378a8 --- /dev/null +++ b/cmd/server/templates/debug.html @@ -0,0 +1,43 @@ + + + + Proxy402 Debugger + + + + + + + + + +
+

Debug x402 Endpoint

+ +

+    
+ + + diff --git a/ui/handler.go b/ui/handler.go index 36d5f80..33edd67 100644 --- a/ui/handler.go +++ b/ui/handler.go @@ -104,6 +104,9 @@ func (h *UIHandler) SetupRoutes(router *gin.Engine) { // Public landing page for non-authenticated users router.GET("/", h.handleLandingPage) + // Debugger page for testing endpoints + router.GET("/debug", h.handleDebug) + // Dashboard for authenticated users router.GET("/dashboard", auth.AuthMiddleware(h.authService), h.handleDashboard) @@ -136,6 +139,11 @@ func (h *UIHandler) handleLandingPage(gCtx *gin.Context) { }) } +// handleDebug renders the debug page used to test x402 endpoints +func (h *UIHandler) handleDebug(gCtx *gin.Context) { + gCtx.HTML(http.StatusOK, "debug.html", gin.H{}) +} + // handleDashboard handles the main dashboard page for authenticated users func (h *UIHandler) handleDashboard(gCtx *gin.Context) { // User is guaranteed to exist due to middleware