MCPcopy Index your code
hub / github.com/git-bug/git-bug / runWebUI

Function runWebUI

commands/webui.go:77–194  ·  view source on GitHub ↗
(env *execenv.Env, opts webUIOptions)

Source from the content-addressed store, hash-verified

75}
76
77func runWebUI(env *execenv.Env, opts webUIOptions) error {
78 if opts.port == 0 {
79 var err error
80 opts.port, err = freeport.GetFreePort()
81 if err != nil {
82 return err
83 }
84 }
85
86 addr := net.JoinHostPort(opts.host, strconv.Itoa(opts.port))
87 webUiAddr := fmt.Sprintf("http://%s", addr)
88 toOpen := webUiAddr
89
90 if len(opts.query) > 0 {
91 // Explicitly set the query parameter instead of going with a default one.
92 toOpen = fmt.Sprintf("%s/?q=%s", webUiAddr, url.QueryEscape(opts.query))
93 }
94
95 router := mux.NewRouter()
96
97 // If the webUI is not read-only, use an authentication middleware with a
98 // fixed identity: the default user of the repo
99 // TODO: support dynamic authentication with OAuth
100 if !opts.readOnly {
101 author, err := identity.GetUserIdentity(env.Repo)
102 if err != nil {
103 return err
104 }
105 router.Use(auth.Middleware(author.Id()))
106 }
107
108 mrc := cache.NewMultiRepoCache()
109
110 _, events := mrc.RegisterDefaultRepository(env.Repo)
111
112 err := execenv.CacheBuildProgressBar(env, events)
113 if err != nil {
114 return err
115 }
116
117 var errOut io.Writer
118 if opts.logErrors {
119 errOut = env.Err
120 }
121
122 graphqlHandler := graphql.NewHandler(mrc, errOut)
123
124 // Routes
125 router.Path("/playground").Handler(playground.Handler("git-bug", "/graphql"))
126 router.Path("/graphql").Handler(graphqlHandler)
127 router.Path("/gitfile/{repo}/{hash}").Handler(httpapi.NewGitFileHandler(mrc))
128 router.Path("/upload/{repo}").Methods("POST").Handler(httpapi.NewGitUploadFileHandler(mrc))
129 router.PathPrefix("/").Handler(webui.NewHandler())
130
131 srv := &http.Server{
132 Addr: addr,
133 Handler: router,
134 }

Callers 1

newWebUICommandFunction · 0.85

Calls 15

GetUserIdentityFunction · 0.92
MiddlewareFunction · 0.92
NewMultiRepoCacheFunction · 0.92
CacheBuildProgressBarFunction · 0.92
NewHandlerFunction · 0.92
NewHandlerFunction · 0.92
closeFunction · 0.85
FatalfMethod · 0.80
RunMethod · 0.80
IdMethod · 0.65
PrintlnMethod · 0.65

Tested by

no test coverage detected