How to use virtual hosts with Iris?

119 Views Asked by At

I'm wondering why the following won't work with Iris (v6.2.0):

import (
    "gopkg.in/kataras/iris.v6"
    "gopkg.in/kataras/iris.v6/adaptors/httprouter"
)

func main() {
    app := iris.New()
    app.Adapt(iris.DevLogger())
    app.Adapt(httprouter.New())

    exampleCom := app.Party("example.com")
    {
        exampleCom.Get("/", func(c *iris.Context) {
            c.Writef("hello from example.com")
        })
    }

    app.Get("/", func(c *iris.Context) {
        c.Writef("hello from everywhere else")
    })

    app.Listen(":3000")
}

I have pointed example.com to localhost in my hosts configuration. Visiting localhost:3000 does give me "hello from everywhere else", but visiting example.com:3000 gives me Iris' 404 page.

0

There are 0 best solutions below