From 580894b1e1ffe9cc04817794491e0f7398538a46 Mon Sep 17 00:00:00 2001 From: goooogs Date: Fri, 7 May 2021 12:32:13 +0800 Subject: [PATCH] Add root-path support --- server/options.go | 1 + server/server.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/options.go b/server/options.go index 3d7f69ca..c7d3a9eb 100644 --- a/server/options.go +++ b/server/options.go @@ -7,6 +7,7 @@ import ( type Options struct { Address string `hcl:"address" flagName:"address" flagSName:"a" flagDescribe:"IP address to listen" default:"0.0.0.0"` Port string `hcl:"port" flagName:"port" flagSName:"p" flagDescribe:"Port number to liten" default:"8080"` + RootPath string `hcl:"root_path" flagName:"root-path" flagDescribe:"Context root path" default:"/"` PermitWrite bool `hcl:"permit_write" flagName:"permit-write" flagSName:"w" flagDescribe:"Permit clients to write to the TTY (BE CAREFUL)" default:"false"` EnableBasicAuth bool `hcl:"enable_basic_auth" default:"false"` Credential string `hcl:"credential" flagName:"credential" flagSName:"c" flagDescribe:"Credential for Basic Authentication (ex: user:pass, default disabled)" default:""` diff --git a/server/server.go b/server/server.go index 6411e714..3f4fae39 100644 --- a/server/server.go +++ b/server/server.go @@ -95,9 +95,9 @@ func (server *Server) Run(ctx context.Context, options ...RunOption) error { counter := newCounter(time.Duration(server.options.Timeout) * time.Second) - path := "/" + path := server.options.RootPath if server.options.EnableRandomUrl { - path = "/" + randomstring.Generate(server.options.RandomUrlLength) + "/" + path = path + randomstring.Generate(server.options.RandomUrlLength) + "/" } handlers := server.setupHandlers(cctx, cancel, path, counter)