getting-started

Getting Started: Serve a Static SPA

This tutorial walks you through serving a static Single Page Application (SPA) with environment variable exposure using servejs.

Prerequisites

  • Go 1.25+
  • A built SPA (e.g., React, Vue, Svelte, etc.)

Steps

  1. Install servejs

    1
    
    go get git.home.luguber.info/inful/servejs
  2. Write a main.go

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    
    package main
    
    import (
        "log"
        "net/http"
        "git.home.luguber.info/inful/servejs"
    )
    
    func main() {
        handler := servejs.NewDir("./dist")
        log.Println("Serving on :8080...")
        log.Fatal(http.ListenAndServe(":8080", handler))
    }
  3. Run your server

    1
    
    go run main.go
  4. Visit your app

    Open http://localhost:8080 in your browser.

Next Steps