fiber icon indicating copy to clipboard operation
fiber copied to clipboard

🚀 [Feature]: Route Domain() func

Open kadirgun opened this issue 1 year ago • 13 comments

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.

kadirgun avatar Sep 04 '23 19:09 kadirgun

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

welcome[bot] avatar Sep 04 '23 19:09 welcome[bot]

nice idea related: https://github.com/gofiber/fiber/issues/750 https://github.com/gofiber/fiber/issues/1409

ReneWerner87 avatar Sep 05 '23 06:09 ReneWerner87

Should the domain string be added before each "/" just like https://github.com/gofiber/fiber/blob/6d34e23815eb6cf8cb4d0a1748a1c033e592df32/router.go#L243C1-L249C3

AKARSHITJOSHI avatar Sep 11 '23 07:09 AKARSHITJOSHI

would not want to mix the routing of the paths and this feature, more like in the proposal

ReneWerner87 avatar Sep 11 '23 07:09 ReneWerner87

Is anyone working on this yet? If not I am available.

joey1123455 avatar Oct 05 '23 07:10 joey1123455

@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 avatar Oct 22 '23 13:10 joey1123455

@joey1123455 - did you finish working on this feature?

championswimmer avatar Dec 30 '23 06:12 championswimmer

@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 avatar Dec 30 '23 07:12 joey1123455

@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

championswimmer avatar Dec 30 '23 07:12 championswimmer

@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 avatar Dec 30 '23 07:12 joey1123455

@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 avatar Dec 30 '23 07:12 joey1123455

@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?

championswimmer avatar Dec 30 '23 07:12 championswimmer

@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?

Hmm try it out I was just following the proposed feature specification.

joey1123455 avatar Dec 30 '23 07:12 joey1123455