mirror of
https://github.com/kataras/iris.git
synced 2025-01-24 03:01:03 +01:00
4993918a12
Former-commit-id: 5576c44b64014fb00dd79e618b815b5f52b705e4
40 lines
892 B
Go
40 lines
892 B
Go
package main
|
|
|
|
// go get -u github.com/iris-contrib/middleware/...
|
|
|
|
import (
|
|
"github.com/kataras/iris"
|
|
|
|
"github.com/iris-contrib/middleware/cors"
|
|
)
|
|
|
|
func main() {
|
|
app := iris.New()
|
|
|
|
crs := cors.New(cors.Options{
|
|
AllowedOrigins: []string{"*"}, // allows everything, use that to change the hosts.
|
|
AllowCredentials: true,
|
|
})
|
|
|
|
v1 := app.Party("/api/v1", crs).AllowMethods(iris.MethodOptions) // <- important for the preflight.
|
|
{
|
|
v1.Get("/home", func(ctx iris.Context) {
|
|
ctx.WriteString("Hello from /home")
|
|
})
|
|
v1.Get("/about", func(ctx iris.Context) {
|
|
ctx.WriteString("Hello from /about")
|
|
})
|
|
v1.Post("/send", func(ctx iris.Context) {
|
|
ctx.WriteString("sent")
|
|
})
|
|
v1.Put("/send", func(ctx iris.Context) {
|
|
ctx.WriteString("updated")
|
|
})
|
|
v1.Delete("/send", func(ctx iris.Context) {
|
|
ctx.WriteString("deleted")
|
|
})
|
|
}
|
|
|
|
app.Run(iris.Addr("localhost:8080"))
|
|
}
|