-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathmain.go
47 lines (38 loc) · 1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"github.com/kataras/iris/v12"
"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,
})
app.UseRouter(crs)
// OR per group of routes:
// api := app.Party("/api")
// api.AllowMethods(iris.MethodOptions) <- important for the preflight.
// api.Use(crs)
api := app.Party("/api")
api.Post("/mailer", func(ctx iris.Context) {
var any iris.Map
err := ctx.ReadJSON(&any)
if err != nil {
ctx.StopWithError(iris.StatusBadRequest, err)
return
}
ctx.Application().Logger().Infof("received %#+v", any)
ctx.JSON(iris.Map{"message": "ok"})
})
api.Post("/send", func(ctx iris.Context) {
ctx.WriteString("sent")
})
api.Put("/send", func(ctx iris.Context) {
ctx.WriteString("updated")
})
api.Delete("/send", func(ctx iris.Context) {
ctx.WriteString("deleted")
})
app.Listen(":8080", iris.WithTunneling)
}