From 15c005144b1be51492e8f78ae763fe9b0197d6ed Mon Sep 17 00:00:00 2001 From: SaraJane Date: Tue, 20 Jan 2026 13:11:07 +0000 Subject: [PATCH] debugging --- .../NFT_mint_server/app.js | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/projects/TokenizeRWATemplate-contracts/NFT_mint_server/app.js b/projects/TokenizeRWATemplate-contracts/NFT_mint_server/app.js index a94e7d8..a6e9dcc 100644 --- a/projects/TokenizeRWATemplate-contracts/NFT_mint_server/app.js +++ b/projects/TokenizeRWATemplate-contracts/NFT_mint_server/app.js @@ -11,6 +11,13 @@ dotenv.config() const app = express() +// --- DEBUG: log every request (shows up in Vercel function logs) +app.use((req, _res, next) => { + console.log(`[REQ] ${req.method} ${req.url} origin=${req.headers.origin || 'none'}`) + next() +}) + + /** * CORS * - Allows localhost dev @@ -109,6 +116,59 @@ function safeJsonParse(v: unknown, fallback: any) { } } +const app = express() + +// 1️⃣ (optional) DEBUG: log every request +app.use((req, _res, next) => { + console.log(`[REQ] ${req.method} ${req.url} origin=${req.headers.origin || 'none'}`) + next() +}) + +// 2️⃣ CORS +app.use(cors(corsOptions)) +app.options('*', cors(corsOptions)) + +// 3️⃣ Body parsers +app.use(express.json()) + +// 4️⃣ Health +app.get('/health', (_req, res) => { + res.set('Cache-Control', 'no-store') + res.status(200).json({ ok: true, ts: Date.now() }) +}) + +// 🔎 5️⃣ DEBUG ROUTE — ADD IT HERE +app.get('/api/debug', (req, res) => { + res.json({ + ok: true, + message: 'Reached Express', + url: req.url, + origin: req.headers.origin || null, + }) +}) + +// 6️⃣ Upload middleware +const upload = multer({ + storage: multer.memoryStorage(), + limits: { fileSize: 10 * 1024 * 1024 }, +}) + +// 7️⃣ Real endpoint +app.post('/api/pin-image', upload.single('file'), async (req, res) => { + // ... your existing logic +}) + +// 8️⃣ (optional) DEBUG: catch-all 404 at VERY bottom +app.use((req, res) => { + console.log(`[MISS] ${req.method} ${req.url}`) + res.status(404).json({ + error: 'NOT_FOUND_IN_EXPRESS', + method: req.method, + url: req.url, + }) +}) + + app.post('/api/pin-image', upload.single('file'), async (req, res) => { try { const file = req.file @@ -154,4 +214,15 @@ app.post('/api/pin-image', upload.single('file'), async (req, res) => { } }) +// --- DEBUG: catch-all so we can see if Express is being hit at all +app.use((req, res) => { + console.log(`[MISS] ${req.method} ${req.url} (no route matched)`) + res.status(404).json({ + error: 'NOT_FOUND_IN_EXPRESS', + method: req.method, + url: req.url, + }) +}) + + export default app