Skip to content

Middleware

Static

Serve static files from middleware.

Static serves files from app.Use, and falls through to your routes when a requested file does not exist. For a dedicated asset prefix, the app-level helpers are usually simpler.

app.Use(middleware.Static("./public"))

Serve from a prefix:

app.Use(middleware.StaticFrom("/assets", "./public"))

Serve from an fs.FS:

app.Use(middleware.StaticFS(embeddedFiles))

By default, Static falls through to the next handler when a file is not found.

app.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Root: "./public",
Prefix: "/assets",
NextOnNotFound: true,
}))