Skip to content

Commit

Permalink
finally!
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptnull committed Dec 21, 2024
1 parent 5508da8 commit 49bf320
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func runServer(cmd *cobra.Command, args []string) {
go func() {
webServerAddr := ":5555" // TODO make this come from a config
log.Println("Starting webapp server at", webServerAddr)
webServer := webapp.New(webServerAddr)
webServer, err := webapp.New(webServerAddr)
if err != nil {
log.Fatalln("Error creating web app server", err)
}
if err := webServer.ListenAndServe(); err != nil {
log.Fatalln("Error starting web server", err)
}
Expand Down
18 changes: 13 additions & 5 deletions webapp/webapp.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package webapp

import (
"embed"
"fmt"
"io/fs"
"net/http"
)

type Server struct {
*http.Server
}

func New(addr string) *Server {
//go:embed dist

Check failure on line 14 in webapp/webapp.go

View workflow job for this annotation

GitHub Actions / lint

pattern dist: no matching files found (typecheck)
var WebAssets embed.FS

func New(addr string) (*Server, error) {
routes := http.NewServeMux()

routes.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "TODO")
})
reactApp, err := fs.Sub(WebAssets, "dist")
if err != nil {
return nil, fmt.Errorf("error finding the dist folder: %w", err)
}

routes.Handle("/", http.FileServerFS(reactApp))

return &Server{
Server: &http.Server{
Addr: addr,
Handler: routes,
},
}
}, nil
}

0 comments on commit 49bf320

Please sign in to comment.