1
0
forked from MTSR/mapserver

webserver stub

This commit is contained in:
NatureFreshMilk 2019-01-18 10:11:40 +01:00
parent aa7374a899
commit 4b5b63fe9e
4 changed files with 30 additions and 19 deletions

View File

@ -9,12 +9,14 @@ import (
type Config struct {
Port int `json:"port"`
EnableInitialRendering bool `json:"enableinitialrendering"`
Webdev bool `json:"webdev"`
}
func ParseConfig(filename string) (*Config, error) {
cfg := Config{
Port: 8080,
EnableInitialRendering: true,
Webdev: false,
}
info, err := os.Stat(filename)

View File

@ -1 +1,5 @@
{}
{
"port": 8080,
"enableinitialrendering": false,
"webdev": false
}

1
static/index.html Normal file
View File

@ -0,0 +1 @@
Root

View File

@ -1,27 +1,31 @@
package web
import (
"github.com/sirupsen/logrus"
"mapserver/app"
"net/http"
"strconv"
"fmt"
"fmt"
"github.com/sirupsen/logrus"
"mapserver/app"
"mapserver/vfs"
"net/http"
"strconv"
)
func Serve(ctx *app.App){
fields := logrus.Fields{
"port": ctx.Config.Port,
}
logrus.WithFields(fields).Info("Starting http server")
func Serve(ctx *app.App) {
fields := logrus.Fields{
"port": ctx.Config.Port,
"webdev": ctx.Config.Webdev,
}
logrus.WithFields(fields).Info("Starting http server")
mux := http.NewServeMux()
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Welcome to my website!")
})
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
err := http.ListenAndServe(":" + strconv.Itoa(ctx.Config.Port), mux)
if err != nil {
panic(err)
}
mux.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Api endpoint")
})
err := http.ListenAndServe(":"+strconv.Itoa(ctx.Config.Port), mux)
if err != nil {
panic(err)
}
}