gofiber / fiber

⚡️ Express inspired web framework written in Go

Home Page:https://gofiber.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🤗 [Question]: get param from path for proxy pass request

a-devops-guy opened this issue · comments

Question Description

is it possible to get a param from url path in this case tenant for proxy do handlers

fiber version v2.52.1

Code Snippet (optional)

app.All("/auth/admin/:tenant/*", ProxyHandlerConfig.Proxy)

func (config *Config) Proxy(c *fiber.Ctx) error {
	ctx := c.UserContext()

	proxy.WithTlsConfig(&tls.Config{
		InsecureSkipVerify: true,
	})

	tenant := config.GetTenant(ctx, c)
	log.Infof("tenant", tenant)
	log.Info("tenant", c.Params("tenant"))

	if *tenant != c.Params("tenant") {
    return fiber.NewError(fiber.StatusBadRequest, "url malformed")
	}

	if err := proxy.Do(c, *config.CoreEndpoint+c.Path(), config.ProxyConfig); err != nil {
		return err
	}

	return nil
}

func (config *Config) GetTenant(ctx context.Context, c *fiber.Ctx) *string {
	domain := c.Hostname()

	tenantSplices := strings.Split(c.Hostname(), ".")
	tenant := &tenantSplices[0]

	return tenant
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord