nandi/oripublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/nandi/ori.git
git clone ssh://git@rickub.com/nandi/ori.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

forked from bots-garden/ori

embed.go · 31 lines · 872 BGo Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Package ui embeds the production build of the single-page application so
// the ori server ships as a single binary.
//
// The Vite build writes to ui/dist (run `make build-ui`). When dist only
// contains the committed .gitkeep placeholder, the server still compiles and
// answers with an explanatory error page instead of the SPA.
package ui

import (
	"embed"
	"io/fs"
)

//go:embed all:dist
var dist embed.FS

// Dist returns the embedded SPA build as a filesystem rooted at the dist
// directory, i.e. index.html lives at the root of the returned fs.FS.
//
// Example:
//
//	http.Handle("/", http.FileServerFS(ui.Dist()))
func Dist() fs.FS {
	sub, err := fs.Sub(dist, "dist")
	if err != nil {
		// The dist directory is embedded at compile time; its absence is a
		// build-system bug, not a runtime condition a caller could handle.
		panic(err)
	}
	return sub
}