gonextstatic

package module
v0.0.0-...-d431fbd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 9 Imported by: 0

README

Serve NextJS app from Go

This little library makes it easy to serve NextJS apps that have been built using the output: "export" option from your Go app.

The main purpose is to resolve dynamic route segments and match the request path to the correct HTML file. For this it does some basic pattern matching which probably doesn't cover all edge cases.

I mainly built this so I can bundle a NextJS app together with the Go backend in a single binary.

import gonextstatic "github.com/merlinfuchs/go-next-static"

func main() {
    // Use go:embed instead to embed the files in the binary
	nextFiles := os.DirFS("out")

	handler, err := gonextstatic.NewHandler(nextFiles.(fs.StatFS))
	if err != nil {
		panic(err)
	}

	http.ListenAndServe(":8080", handler)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(f fs.FS) (*Handler, error)

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(res http.ResponseWriter, req *http.Request)

type Route

type Route struct {
	RoutePattern *regexp.Regexp
	FilePath     string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL