mirror of
https://github.com/yudai/gotty.git
synced 2026-02-10 02:14:21 +01:00
Merge branch 'pr/sehaas/294'
This commit is contained in:
commit
e988349add
7 changed files with 102 additions and 20 deletions
|
|
@ -28,9 +28,10 @@ type Server struct {
|
|||
factory Factory
|
||||
options *Options
|
||||
|
||||
upgrader *websocket.Upgrader
|
||||
indexTemplate *template.Template
|
||||
titleTemplate *noesctmpl.Template
|
||||
upgrader *websocket.Upgrader
|
||||
indexTemplate *template.Template
|
||||
titleTemplate *noesctmpl.Template
|
||||
manifestTemplate *template.Template
|
||||
}
|
||||
|
||||
// New creates a new instance of Server.
|
||||
|
|
@ -52,6 +53,15 @@ func New(factory Factory, options *Options) (*Server, error) {
|
|||
panic("index template parse failed") // must be valid
|
||||
}
|
||||
|
||||
manifestData, err := Asset("static/manifest.json")
|
||||
if err != nil {
|
||||
panic("manifest not found") // must be in bindata
|
||||
}
|
||||
manifestTemplate, err := template.New("manifest").Parse(string(manifestData))
|
||||
if err != nil {
|
||||
panic("manifest template parse failed") // must be valid
|
||||
}
|
||||
|
||||
titleTemplate, err := noesctmpl.New("title").Parse(options.TitleFormat)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to parse window title format `%s`", options.TitleFormat)
|
||||
|
|
@ -78,8 +88,9 @@ func New(factory Factory, options *Options) (*Server, error) {
|
|||
Subprotocols: webtty.Protocols,
|
||||
CheckOrigin: originChekcer,
|
||||
},
|
||||
indexTemplate: indexTemplate,
|
||||
titleTemplate: titleTemplate,
|
||||
indexTemplate: indexTemplate,
|
||||
titleTemplate: titleTemplate,
|
||||
manifestTemplate: manifestTemplate,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -190,7 +201,9 @@ func (server *Server) setupHandlers(ctx context.Context, cancel context.CancelFu
|
|||
siteMux.Handle(pathPrefix+"js/", http.StripPrefix(pathPrefix, staticFileHandler))
|
||||
siteMux.Handle(pathPrefix+"favicon.png", http.StripPrefix(pathPrefix, staticFileHandler))
|
||||
siteMux.Handle(pathPrefix+"css/", http.StripPrefix(pathPrefix, staticFileHandler))
|
||||
siteMux.Handle(pathPrefix+"icon_192.png", http.StripPrefix(pathPrefix, staticFileHandler))
|
||||
|
||||
siteMux.HandleFunc(pathPrefix+"manifest.json", server.handleManifest)
|
||||
siteMux.HandleFunc(pathPrefix+"auth_token.js", server.handleAuthToken)
|
||||
siteMux.HandleFunc(pathPrefix+"config.js", server.handleConfig)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue