mapserver/server/web/serve.go

41 lines
876 B
Go
Raw Normal View History

2019-01-18 09:30:51 +01:00
package web
import (
2019-01-18 10:11:40 +01:00
"github.com/sirupsen/logrus"
"mapserver/app"
"mapserver/vfs"
"net/http"
"strconv"
2019-01-18 09:30:51 +01:00
)
2019-01-18 10:11:40 +01:00
func Serve(ctx *app.App) {
fields := logrus.Fields{
"port": ctx.Config.Port,
"webdev": ctx.Config.Webdev,
}
logrus.WithFields(fields).Info("Starting http server")
2019-01-18 09:30:51 +01:00
2019-01-18 10:11:40 +01:00
mux := http.NewServeMux()
2019-01-18 09:30:51 +01:00
2019-01-18 10:11:40 +01:00
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
2019-01-18 11:04:37 +01:00
mux.Handle("/api/tile/", &Tiles{ctx: ctx})
2019-01-18 11:09:16 +01:00
mux.Handle("/api/config", &ConfigHandler{ctx: ctx})
2019-01-28 10:42:07 +01:00
mux.Handle("/api/mapobjects", &MapObjects{ctx: ctx})
2019-01-22 16:36:50 +01:00
ws := NewWS(ctx)
mux.Handle("/api/ws", ws)
2019-01-28 13:31:48 +01:00
ctx.Tilerenderer.Eventbus.AddListener(ws)
2019-01-28 14:33:32 +01:00
ctx.WebEventbus.AddListener(ws)
2019-01-18 11:04:37 +01:00
if ctx.Config.WebApi.EnableMapblock {
2019-01-23 13:22:47 +01:00
//mapblock endpoint
2019-01-18 11:04:37 +01:00
mux.Handle("/api/mapblock/", &MapblockHandler{ctx: ctx})
}
2019-01-18 10:11:40 +01:00
err := http.ListenAndServe(":"+strconv.Itoa(ctx.Config.Port), mux)
if err != nil {
panic(err)
}
2019-01-18 09:30:51 +01:00
}