Add missing files...
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/render"
|
||||
)
|
||||
|
||||
type LogEntry struct {
|
||||
Source string `json:"source"`
|
||||
Level string `json:"level"`
|
||||
Message string `json:"message"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
func handleLogsEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
var messages []LogEntry
|
||||
|
||||
if err := render.DecodeJSON(r.Body, &messages); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
for _, message := range messages {
|
||||
remoteAddrPieces := strings.Split(r.RemoteAddr, ":")
|
||||
log.Printf("[Client %s] [%s %s] %s (%s)", remoteAddrPieces[0], message.Source, message.Level, message.Message, utcDateString(message.Timestamp))
|
||||
}
|
||||
render.PlainText(w, r, "OK")
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/render"
|
||||
)
|
||||
|
||||
// ManifestIcon represents an icon in the PWA manifest
|
||||
type ManifestIcon struct {
|
||||
Src string `json:"src"`
|
||||
Type string `json:"type"`
|
||||
Sizes string `json:"sizes"`
|
||||
}
|
||||
|
||||
// Manifest represents the structure of a PWA manifest.json file
|
||||
type Manifest struct {
|
||||
ShortName string `json:"short_name"`
|
||||
Name string `json:"name"`
|
||||
Icons []ManifestIcon `json:"icons"`
|
||||
CaptureLinks string `json:"capture_links"`
|
||||
StartURL string `json:"start_url"`
|
||||
Display string `json:"display"`
|
||||
DisplayOverride []string `json:"display_override"`
|
||||
Scope string `json:"scope"`
|
||||
ThemeColor string `json:"theme_color"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// Generate PWA manifest.json with dynamic values
|
||||
func manifestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
spaceConfig := spaceConfigFromContext(r.Context())
|
||||
config := serverConfigFromContext(r.Context())
|
||||
manifest := Manifest{
|
||||
ShortName: spaceConfig.SpaceName,
|
||||
Name: spaceConfig.SpaceName,
|
||||
Icons: []ManifestIcon{
|
||||
{
|
||||
Src: "/.client/logo-dock.png",
|
||||
Type: "image/png",
|
||||
Sizes: "512x512",
|
||||
},
|
||||
},
|
||||
CaptureLinks: "new-client",
|
||||
StartURL: "/#boot",
|
||||
Display: "standalone",
|
||||
DisplayOverride: []string{"window-controls-overlay"},
|
||||
Scope: "/",
|
||||
ThemeColor: "#e1e1e1",
|
||||
Description: spaceConfig.SpaceDescription,
|
||||
}
|
||||
|
||||
if config.HostURLPrefix != "" {
|
||||
manifest.Icons[0].Src = config.HostURLPrefix + manifest.Icons[0].Src
|
||||
manifest.StartURL = config.HostURLPrefix + manifest.StartURL
|
||||
manifest.Scope = config.HostURLPrefix + manifest.Scope
|
||||
}
|
||||
|
||||
render.JSON(w, r, manifest)
|
||||
}
|
||||
Reference in New Issue
Block a user