mirror of
https://github.com/yudai/gotty.git
synced 2025-12-24 11:20:13 +01:00
add api-prefix flag for nginx path redirect
This commit is contained in:
parent
a080c85cbc
commit
c5ef9697fd
3 changed files with 8 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
#  GoTTY - Share your terminal as a web application
|
||||
|
||||
[][release]
|
||||
|
|
@ -51,6 +52,7 @@ By default, GoTTY starts a web server at port 8080. Open the URL on your web bro
|
|||
--port value, -p value Port number to liten (default: "8080") [$GOTTY_PORT]
|
||||
--permit-write, -w Permit clients to write to the TTY (BE CAREFUL) [$GOTTY_PERMIT_WRITE]
|
||||
--credential value, -c value Credential for Basic Authentication (ex: user:pass, default disabled) [$GOTTY_CREDENTIAL]
|
||||
--api-prefix Add a prefix string for service [$GOTTY_API_PREFIX]
|
||||
--random-url, -r Add a random string to the URL [$GOTTY_RANDOM_URL]
|
||||
--random-url-length value Random URL length (default: 8) [$GOTTY_RANDOM_URL_LENGTH]
|
||||
--tls, -t Enable TLS/SSL [$GOTTY_TLS]
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ type Options struct {
|
|||
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:""`
|
||||
ApiPrefix string `hcl:"api_prefix" flagName:"api-prefix" flagDescribe:"Add a string to the URL" default:""`
|
||||
EnableRandomUrl bool `hcl:"enable_random_url" flagName:"random-url" flagSName:"r" flagDescribe:"Add a random string to the URL" default:"false"`
|
||||
RandomUrlLength int `hcl:"random_url_length" flagName:"random-url-length" flagDescribe:"Random URL length" default:"8"`
|
||||
EnableTLS bool `hcl:"enable_tls" flagName:"tls" flagSName:"t" flagDescribe:"Enable TLS/SSL" default:"false"`
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ import (
|
|||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
noesctmpl "text/template"
|
||||
"time"
|
||||
|
||||
|
|
@ -96,6 +98,9 @@ func (server *Server) Run(ctx context.Context, options ...RunOption) error {
|
|||
counter := newCounter(time.Duration(server.options.Timeout) * time.Second)
|
||||
|
||||
path := "/"
|
||||
if strings.TrimSpace(server.options.ApiPrefix) != "" {
|
||||
path = fmt.Sprintf(`/%s/`, strings.TrimSpace(server.options.ApiPrefix))
|
||||
}
|
||||
if server.options.EnableRandomUrl {
|
||||
path = "/" + randomstring.Generate(server.options.RandomUrlLength) + "/"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue