webserver stub
This commit is contained in:
parent
aa7374a899
commit
4b5b63fe9e
@ -9,12 +9,14 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
EnableInitialRendering bool `json:"enableinitialrendering"`
|
EnableInitialRendering bool `json:"enableinitialrendering"`
|
||||||
|
Webdev bool `json:"webdev"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseConfig(filename string) (*Config, error) {
|
func ParseConfig(filename string) (*Config, error) {
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
Port: 8080,
|
Port: 8080,
|
||||||
EnableInitialRendering: true,
|
EnableInitialRendering: true,
|
||||||
|
Webdev: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := os.Stat(filename)
|
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
|
40
web/serve.go
40
web/serve.go
@ -1,27 +1,31 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
"fmt"
|
||||||
"mapserver/app"
|
"github.com/sirupsen/logrus"
|
||||||
"net/http"
|
"mapserver/app"
|
||||||
"strconv"
|
"mapserver/vfs"
|
||||||
"fmt"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Serve(ctx *app.App){
|
func Serve(ctx *app.App) {
|
||||||
fields := logrus.Fields{
|
fields := logrus.Fields{
|
||||||
"port": ctx.Config.Port,
|
"port": ctx.Config.Port,
|
||||||
}
|
"webdev": ctx.Config.Webdev,
|
||||||
logrus.WithFields(fields).Info("Starting http server")
|
}
|
||||||
|
logrus.WithFields(fields).Info("Starting http server")
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
|
||||||
fmt.Fprint(w, "Welcome to my website!")
|
|
||||||
})
|
|
||||||
|
|
||||||
err := http.ListenAndServe(":" + strconv.Itoa(ctx.Config.Port), mux)
|
mux.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
fmt.Fprint(w, "Api endpoint")
|
||||||
panic(err)
|
})
|
||||||
}
|
|
||||||
|
err := http.ListenAndServe(":"+strconv.Itoa(ctx.Config.Port), mux)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user