server: set payload if request body present
This commit is contained in:
parent
32acd23f26
commit
89abbb79dd
2 changed files with 6 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -70,8 +71,11 @@ func handleMsg(ctx lib.Context, cfg *mhSpec, gc *gin.Context) {
|
|||
head := strings.Split(gc.Param("msg"), "/")[1:]
|
||||
cctx := ctx.ChildContext(cfg)
|
||||
msg := message.New(head...).WithSender(cctx)
|
||||
// if gc.Request.Method == "POST" && data != "": msg.WithPayload(data)
|
||||
logging.DebugM(cctx, msg).Msg("server.handleMessage")
|
||||
if body, _ := ioutil.ReadAll(gc.Request.Body); len(body) > 0 {
|
||||
pl := message.PayloadFromJson[lib.Data](string(body))
|
||||
msg.WithPayload(pl)
|
||||
}
|
||||
logging.DebugM(cctx, msg).Msg("server.handleMsg")
|
||||
var proc msgProc
|
||||
for _, act := range action.Select(cctx, msg) {
|
||||
act.Handle()
|
||||
|
|
|
@ -26,8 +26,6 @@ func Config() lib.Config {
|
|||
}
|
||||
app_c.AddAction("demo", action.Base(action.Forward, "test-receiver"))
|
||||
|
||||
//server_amh := server.MsgHandler()
|
||||
//server_amh.AddActionProc("demo", server.Async, "test-receiver")
|
||||
server_c := b("server", server.Start(
|
||||
(&server.Cfg{Port: ovr("8123", SERVER_PORT)}).
|
||||
AddRoute("/docs", server.FileServer("html")).
|
||||
|
|
Loading…
Add table
Reference in a new issue