Skip to content
Discussion options

You must be logged in to vote

Do you want to create SPA (single-page-application) where application checks if request path exists and serves that static file or if it does not will reserve index.html as fallback?

There are many ways to achieve this, one is to have Filesystem that falls back to index.html which is served from in-memory fs

package main

import (
	"embed"
	"fmt"
	"io/fs"
	"log/slog"
	"net/http"
	"strings"

	"github.com/labstack/echo/v5"
	"github.com/spf13/afero"
)

//go:embed dist/public
var distAssets embed.FS

type overlayFS struct {
	primary  fs.FS
	fallback fs.FS
}

func (o overlayFS) Open(name string) (fs.File, error) {
	if name == "index.html" {
		return o.fallback.Open(name)
	}
	f, err := o.primary.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kaaax0815
Comment options

@aldas
Comment options

aldas Feb 2, 2026
Maintainer

Answer selected by kaaax0815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants