Skip to content

Commit d03aac3

Browse files
authored
Merge pull request #312 from docker/alias-v1-engines-to-v1
Alias /engines/v1 to /v1
2 parents d94f4f8 + 654bb0b commit d03aac3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"net"
66
"net/http"
7+
"net/url"
78
"os"
89
"os/signal"
910
"path/filepath"
@@ -26,6 +27,27 @@ import (
2627

2728
var 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+
2951
func 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

Comments
 (0)