Skip to content

Commit

Permalink
Merge pull request #319 from Red-GV/hotel-reservation-html-fix
Browse files Browse the repository at this point in the history
fix: add missing html and css files to frontend binary
  • Loading branch information
cdelimitrou authored Apr 9, 2024
2 parents bb15fe8 + 586d741 commit 2fa49a1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion hotelReservation/services/frontend/server.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package frontend

import (
"embed"
"encoding/json"
"fmt"
"io/fs"
"net/http"
"strconv"

Expand All @@ -24,6 +26,11 @@ import (
"github.com/opentracing/opentracing-go"
)

var (
//go:embed static/*
content embed.FS
)

// Server implements frontend service
type Server struct {
searchClient search.SearchClient
Expand All @@ -46,6 +53,12 @@ func (s *Server) Run() error {
return fmt.Errorf("Server port must be set")
}

log.Info().Msg("Loading static content...")
staticContent, err := fs.Sub(content, "static")
if err != nil {
return err
}

log.Info().Msg("Initializing gRPC clients...")
if err := s.initSearchClient("srv-search"); err != nil {
return err
Expand Down Expand Up @@ -79,7 +92,7 @@ func (s *Server) Run() error {

log.Trace().Msg("frontend before mux")
mux := tracing.NewServeMux(s.Tracer)
mux.Handle("/", http.FileServer(http.Dir("services/frontend/static")))
mux.Handle("/", http.FileServer(http.FS(staticContent)))
mux.Handle("/hotels", http.HandlerFunc(s.searchHandler))
mux.Handle("/recommendations", http.HandlerFunc(s.recommendHandler))
mux.Handle("/user", http.HandlerFunc(s.userHandler))
Expand Down

0 comments on commit 2fa49a1

Please sign in to comment.