forked from MTSR/mapserver
webserver stub
This commit is contained in:
parent
aa7374a899
commit
4b5b63fe9e
@ -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)
|
||||
|
@ -1 +1,5 @@
|
||||
{}
|
||||
{
|
||||
"port": 8080,
|
||||
"enableinitialrendering": false,
|
||||
"webdev": false
|
||||
}
|
||||
|
1
static/index.html
Normal file
1
static/index.html
Normal file
@ -0,0 +1 @@
|
||||
Root
|
10
web/serve.go
10
web/serve.go
@ -1,23 +1,27 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"mapserver/app"
|
||||
"mapserver/vfs"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
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.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "Welcome to my website!")
|
||||
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
|
||||
|
||||
mux.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "Api endpoint")
|
||||
})
|
||||
|
||||
err := http.ListenAndServe(":"+strconv.Itoa(ctx.Config.Port), mux)
|
||||
|
Loading…
Reference in New Issue
Block a user