44 "context"
55 "net"
66 "net/http"
7+ "net/url"
78 "os"
89 "os/signal"
910 "path/filepath"
@@ -26,6 +27,27 @@ import (
2627
2728var log = logrus .New ()
2829
30+ // V1AliasHandler provides an alias from /v1/ to /engines/v1/ paths
31+ type V1AliasHandler struct {
32+ scheduler http.Handler
33+ }
34+
35+ func (h * V1AliasHandler ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
36+ // Modify the URL path to prepend /engines/ before /v1/
37+ originalPath := r .URL .Path
38+ newPath := inference .InferencePrefix + originalPath // originalPath is like "/v1/models", so result is "/engines/v1/models"
39+
40+ // Create a clone of the request with the modified path
41+ r2 := new (http.Request )
42+ * r2 = * r
43+ r2 .URL = new (url.URL )
44+ * r2 .URL = * r .URL
45+ r2 .URL .Path = newPath
46+
47+ // Pass the modified request to the scheduler
48+ h .scheduler .ServeHTTP (w , r2 )
49+ }
50+
2951func main () {
3052 ctx , cancel := signal .NotifyContext (context .Background (), syscall .SIGINT , syscall .SIGTERM )
3153 defer cancel ()
@@ -154,6 +176,8 @@ func main() {
154176 router .Handle (inference .ModelsPrefix , modelManager )
155177 router .Handle (inference .ModelsPrefix + "/" , modelManager )
156178 router .Handle (inference .InferencePrefix + "/" , scheduler )
179+ // Add /v1 as an alias for /engines/v1
180+ router .Handle ("/v1/" , & V1AliasHandler {scheduler : scheduler })
157181
158182 // Add metrics endpoint if enabled
159183 if os .Getenv ("DISABLE_METRICS" ) != "1" {
0 commit comments