Skip to main content

Svelte + Fiber on Netlify

Github StackBlitz

Netlify Status

A Go Fiber API deployed as a Netlify Function, with a Svelte frontend. The API provides IP geolocation via ip-api.com.

Demo: https://gofiber-svelte.netlify.app/

Prerequisites

  • Go 1.21+
  • Node.js 18+ (for the Svelte frontend)
  • Netlify CLInpm install -g netlify-cli

Local Development

  1. Install frontend dependencies and build the Svelte app:

    npm install
    npm run build
  2. Build the Go function:

    ./build.sh
  3. Start the local dev server:

    netlify dev

    The app will be available at http://localhost:8888.

Deploy to Netlify

Via Netlify CLI

netlify deploy --prod

Via Git

Connect your repository in the Netlify dashboard. The netlify.toml configures the build automatically.

How It Works

  • ./build.sh compiles the Go binary to cmd/gateway/gateway and places it in the functions/ directory.
  • Netlify serves the binary as a Netlify Function.
  • Static files under public/ are served directly (entry point: index.html).
  • API calls to /api/* are redirected server-side to /.netlify/functions/gateway/:splat (status 200).

Project Structure

.
├── adapter/ # AWS Lambda <-> Fiber adapter
├── cmd/gateway/ # Lambda entry point (main.go)
├── handler/ # Fiber route handlers
├── public/ # Compiled Svelte frontend
├── build.sh # Build script for the Go function
└── netlify.toml # Netlify build configuration

Notes

  • Netlify Functions are limited to 125,000 requests/month on the free tier (~2.89 req/min). Response caching with a 10-minute TTL is applied to the geolocation endpoint to stay within limits.