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

What is the best way to handle subdomains? #55

Closed
easyrider opened this issue Aug 9, 2014 · 4 comments
Closed

What is the best way to handle subdomains? #55

easyrider opened this issue Aug 9, 2014 · 4 comments

Comments

@easyrider
Copy link

goji.Get("subdomain.domain.xyz", root)

any idea how to handle this?

@elithrar
Copy link
Contributor

elithrar commented Aug 9, 2014

Did you check the reply to your post on Google Groups? https://groups.google.com/d/topic/golang-nuts/a7-6d1-d11o

@easyrider
Copy link
Author

yes, I have checked it but it doesn't work for me

@zenazn
Copy link
Owner

zenazn commented Aug 10, 2014

Err, this seems to be working for me?

package main

import (
    "net/http"

    "github.com/zenazn/goji"
    "github.com/zenazn/goji/web"
)

func main() {
    mux1 := web.New()
    mux1.Get("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("domain one mux\n"))
    })
    http.Handle("domainone.com/", mux1)

    mux2 := web.New()
    mux2.Get("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("domain two mux\n"))
    })
    http.Handle("domaintwo.com/", mux2)

    goji.Get("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("main mux\n"))
    })
    goji.Serve()
}
$ curl -H "Host: domainone.com" localhost:8000
domain one mux
$ curl -H "Host: domaintwo.com" localhost:8000
domain two mux
$ curl  localhost:8000
main mux

@easyrider
Copy link
Author

Ok, it works. Thank you guys.

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

No branches or pull requests

3 participants