Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

How to Monitor Your SvelteKit API Routes with Vigilmon

How to Monitor Your SvelteKit API Routes with Vigilmon SvelteKit's server routes (+server.ts) handle everything from form submissions to REST API endpoints. When these go down, your app breaks silently. Here's how to k

How to Monitor Your SvelteKit API Routes with Vigilmon

SvelteKit's server routes (+server.ts) handle everything from form submissions to REST API endpoints. When these go down, your app breaks silently. Here's how to keep them monitored with Vigilmon.

Why Monitor SvelteKit API Routes?

SvelteKit server routes are not frontend — they run on Node.js (or edge runtimes) and can fail independently of your UI. A failed +server.ts route means:

  • Form submissions fail silently
  • Data fetching returns 500s
  • Auth flows break
  • Users get no feedback

Setting Up a Health Check Endpoint

Create src/routes/health/+server.ts:

import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';

export const GET: RequestHandler = async () => {
  return json({
    status: 'ok',
    timestamp: new Date().toISOString(),
    version: process.env.APP_VERSION ?? 'unknown'
  });
};

This endpoint will return HTTP 200 with a JSON body when everything is healthy.

Monitoring with Vigilmon

  1. Sign up at vigilmon.online
  2. Click Add Monitor
  3. Configure:
    • URL: https://your-app.vercel.app/health
    • Type: HTTP(S)
    • Interval: 1 minute
    • Expected status: 200
    • Keyword check: "status":"ok"

Vigilmon will ping your health endpoint every minute and alert you instantly if it returns a non-200 status or if the response body doesn't contain your keyword.

Monitoring Individual API Routes

For critical routes like authentication or payment processing:

// src/routes/api/status/+server.ts
import { json } from '@sveltejs/kit';
import { db } from '$lib/server/db';

export const GET: RequestHandler = async () => {
  try {
    // Test DB connection
    await db.execute('SELECT 1');
    return json({ db: 'ok', api: 'ok' });
  } catch (e) {
    return json({ db: 'error', api: 'degraded' }, { status: 503 });
  }
};

Add a Vigilmon monitor for /api/status with keyword check "api":"ok" — if your database goes down, Vigilmon catches it within 60 seconds.

Environment-Specific Monitoring

For multi-environment setups (dev/staging/prod), add separate Vigilmon monitors:

Environment URL Vigilmon Monitor
Production https://app.com/health Alert immediately
Staging https://staging.app.com/health Alert after 5 min

Alert Configuration

Vigilmon supports email, Slack, and webhook alerts. For SvelteKit apps in production:

  • Email: immediate downtime notification
  • Webhook: post to Slack #alerts channel
  • SMS: for critical payment/auth routes

What Vigilmon Monitors

  • HTTP status code (200, 201, etc.)
  • Response time (alert if >2000ms)
  • Response body keyword match
  • SSL certificate expiry
  • Response headers

Summary

SvelteKit API routes are backend services that deserve proper uptime monitoring. With Vigilmon, you get a minute-by-minute health pulse on every critical route, instant alerts when something breaks, and a clear uptime history to share with your team.

Start free at vigilmon.online — no credit card required.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.