From 1e5b3c20f22201c23d66fec57b3830b679f237b0 Mon Sep 17 00:00:00 2001 From: Abhilash Gnan Date: Sun, 3 Nov 2019 12:51:01 +0100 Subject: [PATCH 1/7] fix index.html Signed-off-by: Abhilash Gnan --- .../hotrod/services/frontend/gen_assets.go | 53 ++++++++++--------- .../services/frontend/web_assets/index.html | 7 ++- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/examples/hotrod/services/frontend/gen_assets.go b/examples/hotrod/services/frontend/gen_assets.go index f7510c1ec1d..2dd8d9512e2 100644 --- a/examples/hotrod/services/frontend/gen_assets.go +++ b/examples/hotrod/services/frontend/gen_assets.go @@ -212,33 +212,34 @@ var _escData = map[string]*_escFile{ "/index.html": { name: "index.html", local: "examples/hotrod/services/frontend/web_assets/index.html", - size: 3384, - modtime: 1551364059, + size: 3552, + modtime: 1572778479, compressed: ` -H4sIAAAAAAAC/9RX/1PbOBb/PX/FG23v7FywnRAoNMS54UiX0r0uvUC709vpD7L0YivYkivJgSzD/34j -2wkJlJv9cZsZQHrfP++LXhhntsgnHYBxgZYCy6g2aGNycXUZHB8fvgkG5JEraYExWQq8LZW2BJiSFqWN -ya3gNos5LgXDoL7sgZDCCpoHhtEc40HY34OC3omiKrZJlUFd32mSY9xvnGVIuTsAjK2wOU7eKTu7nEIA -M8HRwKWEKRZU8nHU8BtZw7QoLRjNYpJZW5pRFDHFMVx8q1CvQqaKqDkGw3AQDsJCyHBhyGQcNaqtnVzI -G9CYx8TYVY4mQ7QEMo3zR7sFvWNcholS1lhNS3dx9jeEaBgOw6OIGfNIqx0yYwgIaTHVwq5iYjI6PD4I -/vX5ixBXFz/jLwN+Xryfnd6sWPXu9N0sHe5fFp/Y7e2RksPZF54efKa9j8XVtfkj+uX18TLhbxfZQUWA -aWWM0iIVMiZUKrkqVGXI/0nOnwWxeIph8V0I1+zw4j8i6e8ffVuuFlcf5u8Wlx/ov2/m1W+f7/579+mj -PHt/epTvF2e//XpRnr8pzs+mx7fnv16wj9Oj6zv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+RJ2Pyw+28AAAD//2U/DQ7gDQAA `, }, diff --git a/examples/hotrod/services/frontend/web_assets/index.html b/examples/hotrod/services/frontend/web_assets/index.html index 75ed3a74dda..4a2a1f88540 100644 --- a/examples/hotrod/services/frontend/web_assets/index.html +++ b/examples/hotrod/services/frontend/web_assets/index.html @@ -73,7 +73,12 @@

Rides On Demand

}; console.log(headers); var before = Date.now(); - $.ajax('/dispatch?customer=' + customer + '&nonse=' + Math.random(), { + + // Use current URI as basepath for ajax requests + var pathPrefix = window.location.pathname; + pathPrefix = pathPrefix.length > 1 ? pathPrefix : ''; + + $.ajax(pathPrefix + '/dispatch?customer=' + customer + '&nonse=' + Math.random(), { headers: headers, method: 'GET', success: function(data, textStatus) { From 36c2ecc7b76d70d782534c7e52454b4795d876bd Mon Sep 17 00:00:00 2001 From: Abhilash Gnan Date: Sun, 3 Nov 2019 13:02:26 +0100 Subject: [PATCH 2/7] Add basepath arg Signed-off-by: Abhilash Gnan --- examples/hotrod/cmd/frontend.go | 1 + examples/hotrod/cmd/root.go | 9 +++++++++ examples/hotrod/services/frontend/server.go | 16 +++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/examples/hotrod/cmd/frontend.go b/examples/hotrod/cmd/frontend.go index bdbbf406648..6ff6551af6d 100644 --- a/examples/hotrod/cmd/frontend.go +++ b/examples/hotrod/cmd/frontend.go @@ -38,6 +38,7 @@ var frontendCmd = &cobra.Command{ options.DriverHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(driverPort)) options.CustomerHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(customerPort)) options.RouteHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(routePort)) + options.Basepath = basepath zapLogger := logger.With(zap.String("service", "frontend")) logger := log.NewFactory(zapLogger) diff --git a/examples/hotrod/cmd/root.go b/examples/hotrod/cmd/root.go index a16ee098d77..50e73dbe2c0 100644 --- a/examples/hotrod/cmd/root.go +++ b/examples/hotrod/cmd/root.go @@ -43,6 +43,8 @@ var ( driverPort int frontendPort int routePort int + + basepath string ) // RootCmd represents the base command when called without any subcommands @@ -73,6 +75,9 @@ func init() { RootCmd.PersistentFlags().IntVarP(&frontendPort, "frontend-service-port", "f", 8080, "Port for frontend service") RootCmd.PersistentFlags().IntVarP(&routePort, "route-service-port", "r", 8083, "Port for routing service") + // Flag for serving frontend at custom basepath url + RootCmd.PersistentFlags().StringVarP(&basepath, "basepath", "b", "/", "Basepath for frontend service") + rand.Seed(int64(time.Now().Nanosecond())) logger, _ = zap.NewDevelopment(zap.AddStacktrace(zapcore.FatalLevel)) cobra.OnInitialize(onInitialize) @@ -118,6 +123,10 @@ func onInitialize() { if routePort != 8083 { logger.Info("changing route service port", zap.Int("old", 8083), zap.Int("new", routePort)) } + + if basepath != "/" { + logger.Info("changing basepath for frontend", zap.String("old", "/"), zap.String("new", basepath)) + } } func logError(logger *zap.Logger, err error) error { diff --git a/examples/hotrod/services/frontend/server.go b/examples/hotrod/services/frontend/server.go index 79e72eadd25..70fc2c183a1 100644 --- a/examples/hotrod/services/frontend/server.go +++ b/examples/hotrod/services/frontend/server.go @@ -34,6 +34,7 @@ type Server struct { logger log.Factory bestETA *bestETA assetFS http.FileSystem + basepath string } // ConfigOptions used to make sure service clients @@ -43,31 +44,40 @@ type ConfigOptions struct { DriverHostPort string CustomerHostPort string RouteHostPort string + Basepath string } // NewServer creates a new frontend.Server func NewServer(options ConfigOptions, tracer opentracing.Tracer, logger log.Factory) *Server { assetFS := FS(false) + basepath := options.Basepath return &Server{ hostPort: options.FrontendHostPort, tracer: tracer, logger: logger, bestETA: newBestETA(tracer, logger, options), assetFS: assetFS, + basepath: basepath, } } // Run starts the frontend server func (s *Server) Run() error { mux := s.createServeMux() - s.logger.Bg().Info("Starting", zap.String("address", "http://"+s.hostPort)) + s.logger.Bg().Info("Starting", zap.String("address", "http://"+s.hostPort+s.basepath)) return http.ListenAndServe(s.hostPort, mux) } func (s *Server) createServeMux() http.Handler { mux := tracing.NewServeMux(s.tracer) - mux.Handle("/", http.FileServer(s.assetFS)) - mux.Handle("/dispatch", http.HandlerFunc(s.dispatch)) + switch { + case s.basepath != "/": + mux.Handle(s.basepath, http.StripPrefix(s.basepath, http.FileServer(s.assetFS))) + mux.Handle(s.basepath + "/dispatch", http.HandlerFunc(s.dispatch)) + default: + mux.Handle("/", http.FileServer(s.assetFS)) + mux.Handle("/dispatch", http.HandlerFunc(s.dispatch)) + } return mux } From 5fa1a334d5e58c3bd00558945106d325761f6074 Mon Sep 17 00:00:00 2001 From: Abhilash Gnan Date: Sun, 3 Nov 2019 13:12:32 +0100 Subject: [PATCH 3/7] Minor refactor Signed-off-by: Abhilash Gnan --- examples/hotrod/services/frontend/server.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/hotrod/services/frontend/server.go b/examples/hotrod/services/frontend/server.go index 70fc2c183a1..670d46358ae 100644 --- a/examples/hotrod/services/frontend/server.go +++ b/examples/hotrod/services/frontend/server.go @@ -50,14 +50,13 @@ type ConfigOptions struct { // NewServer creates a new frontend.Server func NewServer(options ConfigOptions, tracer opentracing.Tracer, logger log.Factory) *Server { assetFS := FS(false) - basepath := options.Basepath return &Server{ hostPort: options.FrontendHostPort, tracer: tracer, logger: logger, bestETA: newBestETA(tracer, logger, options), assetFS: assetFS, - basepath: basepath, + basepath: options.Basepath, } } From 96c2ba2773b5ee63a18882a8d62bae8a48974237 Mon Sep 17 00:00:00 2001 From: Abhilash Gnan Date: Mon, 4 Nov 2019 18:30:41 +0100 Subject: [PATCH 4/7] Polish Signed-off-by: Abhilash Gnan --- .../hotrod/services/frontend/gen_assets.go | 54 +++++++++---------- examples/hotrod/services/frontend/server.go | 2 +- .../services/frontend/web_assets/index.html | 2 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/examples/hotrod/services/frontend/gen_assets.go b/examples/hotrod/services/frontend/gen_assets.go index 2dd8d9512e2..314cfac3878 100644 --- a/examples/hotrod/services/frontend/gen_assets.go +++ b/examples/hotrod/services/frontend/gen_assets.go @@ -212,34 +212,34 @@ var _escData = map[string]*_escFile{ "/index.html": { name: "index.html", local: "examples/hotrod/services/frontend/web_assets/index.html", - size: 3552, - modtime: 1572778479, + size: 3548, + modtime: 1572888578, compressed: ` -H4sIAAAAAAAC/9RXX1PbSBJ/96fo0uZO8hlJGEMgxtIWh7OE7GXJGchWbisPo5m2NEaaUWZGtlmK7341 -kmxkSK728eIHmOnu6e5f/7UnmSnyuAcwKdAQoBlRGk3kXF5f+ScnR2/8ofPEFaTAyFlyXJVSGQeoFAaF -iZwVZyaLGC45Rb++7AEX3HCS+5qSHKNhsL8HBVnzoiq6pEqjqu8kyTHab4xlSJg9AEwMNznG76SZXU3B -hxlnqOFKwBQLItgkbPiNrKaKlwa0opGTGVPqcRhSyTBYfK1Q3QdUFmFz9EfBMBgGBRfBQjvxJGyetnpy -Lu5AYR452tznqDNE40CmcP6ktyBrykSQSGm0UaS0F6t/SwhHwSg4DqnWT7TaINXaAS4Mpoqb+8jRGRmd -HPr//PSZ8+vLX/DXIbso3s/O7u5p9e7s3SwdHVwVt3S1OpZiNPvM0sNPZPCxuL7Rf4a/vj5ZJuztIjus -HKBKai0VT7mIHCKkuC9kpZ3/EZy/CmLxHMPimxBu6NHlv3myf3D8dXm/uP4wf7e4+kD+dTevfv+0/s/6 -9qM4f392nB8U57//dllevCkuzqcnq4vfLunH6fHNmnwfwlOCWjA2L3EvqCrO4AEKolIufCPLMQyPyvUp -PPaCTBolmZ9UxkgBD1ASxrhIx3CwbyVopbRUYyilBaJOd5Xsf0vJOJNLVPDw8u2c5wbVGBLF08wI1No7 -Ofpb36r4qVWRy/Q7nv5kePkdVg02bNHazgg3rTFJJLtvU8v4EmhOtI4c25GEC1Rt2ne5dbhIjso0f30u -5tJGl/HlVp6ixbS52m4c2v6DWXAVTINJmA27vMN4gkX8oi2xiCdhdtiR7Lih5Mp54ryEkPsF80dgD7rw -Xz+TbQqgJOIF1X5aJYkRkBhRA6wPSS7pH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VWrHmgklwhGglQxKqDAqPK/p+hpzpEt9gxp/Hy8BO35 +smONg3qedXabatLpzEvBDJcC5lLl1ExLRe3VjZtDFx46AEuqIIYQtlQIwB30qw/8Ewb1v9f97lkjWwpu +NITg5Fw4lqjQlErAB2pSX8lSxG7chV4td9Z57HTsK5ZxFObu7moKYVu0PlIRy9ztNvasLfsmo9rM8GuJ +2lTP+medziuXVFuLdH37zcsln2WpYIVRY8HRwOOR3XBKimRCoNc23QNi10HN6jbq9kup6zObTHcbPBeX +pg7Unju93jYequXhvinPWt97tX0zV6jTC6oghFfuK5e0lhzp+oXCAkXsOu1mqp54jCpSbYwp1wU1LLXF +XNeV7/+m8OsInN7Oo57zpVkltkycrs9SnsUKhdv9rf9ll9Fd0YaAS+MbqhI0vm0fjcbfcq203Z6obPYf +mnp0FhQTVF5Ek4Qm6IzA0ag1lyJ0nsfeOdgGq+Lt3OwAPFrtTAotM/QzmbiNpZ2PEc6lQghhSg36Qq5c +mz6AIIA7jfYbhUJh4G52BVRDRDUW1KS28oEu6HprTDfqLPOjwjlfQwgrLmK58jPJqgbwLdP2r7W9J9i6 +/C0EEhD4sU0bgeNUTr3yrU23xeqBE8RNyn7czaQqQtvg98D5h5BCY0Xe64uDJtxNUEbbw0FFzdGkMh6B +c/n21qlJumQMtR7BroptNg/A4NrcGGpK3d1l0IaDzk2V/nZwmyncyonVsWNUY2M7MsIXI4Ya6r+9Pd+J +byu+7lqn+UEyjiYWbCU9VXxZh2EcRBOgSvGlrW4uoJLZ2uqBA02lt4uorq+MGhRsU/PcCpZXl44dSU6u +vziNS482Uo/ds85jXUitr8jjoP5R978AAAD//wouYFDcDQAA `, }, diff --git a/examples/hotrod/services/frontend/server.go b/examples/hotrod/services/frontend/server.go index 670d46358ae..922914ae8ea 100644 --- a/examples/hotrod/services/frontend/server.go +++ b/examples/hotrod/services/frontend/server.go @@ -44,7 +44,7 @@ type ConfigOptions struct { DriverHostPort string CustomerHostPort string RouteHostPort string - Basepath string + Basepat string } // NewServer creates a new frontend.Server diff --git a/examples/hotrod/services/frontend/web_assets/index.html b/examples/hotrod/services/frontend/web_assets/index.html index 4a2a1f88540..4cc48d5e43a 100644 --- a/examples/hotrod/services/frontend/web_assets/index.html +++ b/examples/hotrod/services/frontend/web_assets/index.html @@ -76,7 +76,7 @@

Rides On Demand

// Use current URI as basepath for ajax requests var pathPrefix = window.location.pathname; - pathPrefix = pathPrefix.length > 1 ? pathPrefix : ''; + pathPrefix = pathPrefix != "/" ? pathPrefix : ''; $.ajax(pathPrefix + '/dispatch?customer=' + customer + '&nonse=' + Math.random(), { headers: headers, From 22e7b438cbefcae0ff712294f05ba8da5bfc6a6b Mon Sep 17 00:00:00 2001 From: Abhilash Gnan Date: Tue, 5 Nov 2019 08:22:03 +0100 Subject: [PATCH 5/7] Fix typos Signed-off-by: Abhilash Gnan --- examples/hotrod/services/frontend/server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/hotrod/services/frontend/server.go b/examples/hotrod/services/frontend/server.go index 922914ae8ea..6b00bd156d6 100644 --- a/examples/hotrod/services/frontend/server.go +++ b/examples/hotrod/services/frontend/server.go @@ -44,7 +44,7 @@ type ConfigOptions struct { DriverHostPort string CustomerHostPort string RouteHostPort string - Basepat string + Basepath string } // NewServer creates a new frontend.Server @@ -72,7 +72,7 @@ func (s *Server) createServeMux() http.Handler { switch { case s.basepath != "/": mux.Handle(s.basepath, http.StripPrefix(s.basepath, http.FileServer(s.assetFS))) - mux.Handle(s.basepath + "/dispatch", http.HandlerFunc(s.dispatch)) + mux.Handle(s.basepath+"/dispatch", http.HandlerFunc(s.dispatch)) default: mux.Handle("/", http.FileServer(s.assetFS)) mux.Handle("/dispatch", http.HandlerFunc(s.dispatch)) From 55883e8226481278aeb8628460f7f075b7d9f070 Mon Sep 17 00:00:00 2001 From: Abhilash Gnan Date: Thu, 14 Nov 2019 19:04:55 +0100 Subject: [PATCH 6/7] use path from stdlib Signed-off-by: Abhilash Gnan --- examples/hotrod/cmd/root.go | 4 ++-- examples/hotrod/services/frontend/gen_assets.go | 2 +- examples/hotrod/services/frontend/server.go | 14 +++++--------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/examples/hotrod/cmd/root.go b/examples/hotrod/cmd/root.go index 50e73dbe2c0..ce4790ff547 100644 --- a/examples/hotrod/cmd/root.go +++ b/examples/hotrod/cmd/root.go @@ -76,7 +76,7 @@ func init() { RootCmd.PersistentFlags().IntVarP(&routePort, "route-service-port", "r", 8083, "Port for routing service") // Flag for serving frontend at custom basepath url - RootCmd.PersistentFlags().StringVarP(&basepath, "basepath", "b", "/", "Basepath for frontend service") + RootCmd.PersistentFlags().StringVarP(&basepath, "basepath", "b", "", "Basepath for frontend service") rand.Seed(int64(time.Now().Nanosecond())) logger, _ = zap.NewDevelopment(zap.AddStacktrace(zapcore.FatalLevel)) @@ -124,7 +124,7 @@ func onInitialize() { logger.Info("changing route service port", zap.Int("old", 8083), zap.Int("new", routePort)) } - if basepath != "/" { + if basepath != "" { logger.Info("changing basepath for frontend", zap.String("old", "/"), zap.String("new", basepath)) } } diff --git a/examples/hotrod/services/frontend/gen_assets.go b/examples/hotrod/services/frontend/gen_assets.go index 314cfac3878..25642423b0d 100644 --- a/examples/hotrod/services/frontend/gen_assets.go +++ b/examples/hotrod/services/frontend/gen_assets.go @@ -213,7 +213,7 @@ var _escData = map[string]*_escFile{ name: "index.html", local: "examples/hotrod/services/frontend/web_assets/index.html", size: 3548, - modtime: 1572888578, + modtime: 1573754547, compressed: ` H4sIAAAAAAAC/9RXX3PbNhJ/16fYQ3NH6mSSkmXHjiyq47NSx+mlzsl2OrlOHkBwRUImAQYA9acef/cb kJRM2clNH1s92MDuYnd/+1capybPJh2AcY6GAkup0mhCcnVz7Z2eHr/xBuSJK2iOIVlyXBVSGQJMCoPC diff --git a/examples/hotrod/services/frontend/server.go b/examples/hotrod/services/frontend/server.go index 6b00bd156d6..4c2ce661279 100644 --- a/examples/hotrod/services/frontend/server.go +++ b/examples/hotrod/services/frontend/server.go @@ -18,6 +18,7 @@ package frontend import ( "encoding/json" "net/http" + "path" "github.com/opentracing/opentracing-go" "go.uber.org/zap" @@ -63,20 +64,15 @@ func NewServer(options ConfigOptions, tracer opentracing.Tracer, logger log.Fact // Run starts the frontend server func (s *Server) Run() error { mux := s.createServeMux() - s.logger.Bg().Info("Starting", zap.String("address", "http://"+s.hostPort+s.basepath)) + s.logger.Bg().Info("Starting", zap.String("address", "http://"+path.Join(s.hostPort, s.basepath))) return http.ListenAndServe(s.hostPort, mux) } func (s *Server) createServeMux() http.Handler { mux := tracing.NewServeMux(s.tracer) - switch { - case s.basepath != "/": - mux.Handle(s.basepath, http.StripPrefix(s.basepath, http.FileServer(s.assetFS))) - mux.Handle(s.basepath+"/dispatch", http.HandlerFunc(s.dispatch)) - default: - mux.Handle("/", http.FileServer(s.assetFS)) - mux.Handle("/dispatch", http.HandlerFunc(s.dispatch)) - } + p := path.Join("/", s.basepath) + mux.Handle(p, http.StripPrefix(p, http.FileServer(s.assetFS))) + mux.Handle(path.Join(p, "/dispatch"), http.HandlerFunc(s.dispatch)) return mux } From d505157bd80dd0e6de2e9ec627e3abfd67a0832f Mon Sep 17 00:00:00 2001 From: Abhilash Gnan Date: Fri, 13 Dec 2019 23:19:33 +0530 Subject: [PATCH 7/7] Update help doc Signed-off-by: Abhilash Gnan --- examples/hotrod/cmd/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/hotrod/cmd/root.go b/examples/hotrod/cmd/root.go index ce4790ff547..494af9ac447 100644 --- a/examples/hotrod/cmd/root.go +++ b/examples/hotrod/cmd/root.go @@ -76,7 +76,7 @@ func init() { RootCmd.PersistentFlags().IntVarP(&routePort, "route-service-port", "r", 8083, "Port for routing service") // Flag for serving frontend at custom basepath url - RootCmd.PersistentFlags().StringVarP(&basepath, "basepath", "b", "", "Basepath for frontend service") + RootCmd.PersistentFlags().StringVarP(&basepath, "basepath", "b", "", `Basepath for frontend service(default "/")`) rand.Seed(int64(time.Now().Nanosecond())) logger, _ = zap.NewDevelopment(zap.AddStacktrace(zapcore.FatalLevel))