Vhost (Virtual host) middleware for Fiber that enables the use of virtual hosts based on the Host Header. It is based on the Express vhost middleware.
func New(config ...Config) func(c *fiber.Ctx) error
type struct Vhost {
Host string
Hostname string
HostnameRegexpString
}
First ensure that the appropiate packages are imported
import (
"github.com/gofiber/fiber/v2"
"github.com/K0enM/fiber_vhost"
)
// Default middleware config
app.Use(fiber_vhost.New())
app.Use(fiber_vhost.New(fiber_vhost.Config{
Hostname: "example.com",
Handler: func(c *fiber.Ctx) error {
return c.SendString("Inside the Vhost Handler")
},
}))
app.Use(fiber_vhost.New(fiber_vhost.Config{
Hostname: "*.example.com",
Handler: func(c *fiber.Ctx) error {
return c.SendString("Matched with a wildcard")
},
}))
app.Use(fiber_vhost.New(fiber_vhost.Config{
HostnameRegexp: "",
Handler: func(c *fiber.Ctx) error {
return c.SendString("Matched with a regexp")
},
}))
app.Use(fiber_vhost.New(fiber_vhost.Config{
Next: func(c *fiber.Ctx) bool {
if c.Get("X-Skip-Vhost") == "true" {
return true
}
return false
},
Hostname: "example.com",
Handler: func(c *fiber.Ctx) error {
return c.SendString("Inside the Vhost Handler")
},
}))
type Config struct {
Next func(c *fiber.Ctx) bool
Hostname string
Handler func(c *fiber.Ctx) error
HostnameRegexp string
}
var ConfigDefault = Config{
Next: nil,
Hostname: "vhost.local",
Handler: func(c *fiber.Ctx) error {
return nil
},
HostnameRegexpString: "",
}
- Create documentation
- Create & check workflows`