mirror of
https://github.com/renorris/openfsd
synced 2026-03-22 14:35:36 +08:00
Changes:
- Implement bootstrapping library for managing several concurrent internal services
- Refactor concurrency model for connections/logical clients and their associated I/O
- Refactor server context singleton
- Refactor error handling
- Most errors are now gracefully sent to the FSD client directly encoded as an $ER packet,
enhancing visibility and debugging
- Most errors are now rightfully treated as non-fatal
- Refactor package/dependency graph
- Refactor calling conventions/interfaces for many packages
- Refactor database package
- Refactor post office
Features:
- Add VATSIM-esque HTTP/JSON "data feed"
- Add ephemeral in-memory database option
- Add user management REST API
- Add improved web interface
- Add MySQL support (drop SQLite support)
71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package web
|
|
|
|
import (
|
|
"github.com/renorris/openfsd/database"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"path/filepath"
|
|
"slices"
|
|
"syscall"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestTemplateServer(tst *testing.T) {
|
|
if !slices.Contains(os.Environ(), "TEMPLATE_SERVER=true") {
|
|
return
|
|
}
|
|
|
|
mux := http.ServeMux{}
|
|
|
|
mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(200)
|
|
if _, err := w.Write(favicon); err != nil {
|
|
log.Println(err)
|
|
}
|
|
})
|
|
|
|
mux.Handle("/static/", http.FileServerFS(StaticFS))
|
|
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
base := filepath.Base(r.URL.Path) + ".html"
|
|
|
|
pageData := DashboardPageData{
|
|
UserRecord: &database.FSDUserRecord{
|
|
CID: 123456,
|
|
Email: "example@mail.com",
|
|
FirstName: "Foo",
|
|
LastName: "Bar",
|
|
Password: "",
|
|
FSDPassword: "plaitextfsdpassword",
|
|
NetworkRating: 12,
|
|
CreatedAt: time.Time{},
|
|
UpdatedAt: time.Time{},
|
|
},
|
|
}
|
|
|
|
if err := RenderTemplate(w, base, pageData); err != nil {
|
|
w.WriteHeader(404)
|
|
log.Println(err)
|
|
return
|
|
}
|
|
})
|
|
|
|
server := http.Server{
|
|
Addr: "localhost:8080",
|
|
Handler: &mux,
|
|
}
|
|
|
|
go func() {
|
|
if err := server.ListenAndServe(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}()
|
|
|
|
sigChan := make(chan os.Signal, 1)
|
|
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
|
|
<-sigChan
|
|
}
|