fiber
fiber copied to clipboard
🚀 [Feature]: Route Domain() func
Feature Description
In projects using multiple domains, the easy-to-use Domain() function can be added.
Additional Context (optional)
I know there are manual solutions, but they are not easy to use.
Code Snippet (optional)
package main
import "github.com/gofiber/fiber/v2"
import "log"
func main() {
app := fiber.New()
app.Domain(":username.blog.example.com").Get("/*path", func(c *fiber.Ctx) error {
username := c.Params("username")
return c.SendString(username + "'s blog page")
})
log.Fatal(app.Listen(":3000"))
}
Checklist:
- [X] I agree to follow Fiber's Code of Conduct.
- [X] I have checked for existing issues that describe my suggestion prior to opening this one.
- [X] I understand that improperly formatted feature requests 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
nice idea related: https://github.com/gofiber/fiber/issues/750 https://github.com/gofiber/fiber/issues/1409
Should the domain string be added before each "/" just like https://github.com/gofiber/fiber/blob/6d34e23815eb6cf8cb4d0a1748a1c033e592df32/router.go#L243C1-L249C3
would not want to mix the routing of the paths and this feature, more like in the proposal
Is anyone working on this yet? If not I am available.
@ReneWerner87 hi Rene, I am almost done with the feature. I just wanted to ask how are parameters passed into the ctx.route.Params and ctx.Values
@joey1123455 - did you finish working on this feature?
@joey1123455 - did you finish working on this feature?
I am stuck on passing the dynamic sub domain to the context object as a param but I'm done with everything else
@joey1123455 - any place you have a branch with WIP? Can help on this. I am using Fiber in a project and I need this feature - would be more than happy to help add it to Fiber
@joey1123455 - any place you have a branch with WIP? Can help on this. I am using Fiber in a project and I need this feature - would be more than happy to help add it to Fiber
https://github.com/joey1123455/fiber/tree/app-Domain
@joey1123455 - any place you have a branch with WIP? Can help on this. I am using Fiber in a project and I need this feature - would be more than happy to help add it to Fiber
https://github.com/joey1123455/fiber/tree/app-Domain/middleware%2FsubDomains
I'm stuck here writing a middleware that routes the request to the correct sub app for each sub domain. The router works, its just passing the dynamic domain to the ctx object I can't wrap my head over
@joey1123455 - quick (possibly dumb) question - once handling wildcard domains is possible (using your code), why not just get the subdomains from ctx.Subdomains()
?
I would rather say that ctx.Params()
is NOT the correct place to get this info because Params
is for path params.
It will also create conflict for api.example.com/api
= {sub}.example.com/:path
kind of cases right?
@joey1123455 - quick (possibly dumb) question - once handling wildcard domains is possible (using your code), why not just get the subdomains from
ctx.Subdomains()
?I would rather say that
ctx.Params()
is NOT the correct place to get this info becauseParams
is for path params.It will also create conflict for
api.example.com/api
={sub}.example.com/:path
kind of cases right?
Hmm try it out I was just following the proposed feature specification.