Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
a-devops-guy opened this issue Apr 23, 2024 · 1 comment
Open
3 tasks done

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

a-devops-guy opened this issue Apr 23, 2024 · 1 comment

Comments

@a-devops-guy
Copy link

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.
Copy link

welcome bot commented Apr 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant