9
9
"strings"
10
10
"time"
11
11
12
+ "github.com/coder/coder/coderd/httpapi"
13
+
12
14
"github.com/go-chi/chi/v5"
13
15
"github.com/google/uuid"
14
16
"github.com/prometheus/client_golang/prometheus"
@@ -57,6 +59,7 @@ type Options struct {
57
59
58
60
APIRateLimit int
59
61
SecureAuthCookie bool
62
+ DisablePathApps bool
60
63
61
64
ProxySessionToken string
62
65
}
@@ -156,9 +159,8 @@ func New(opts *Options) (*Server, error) {
156
159
WorkspaceConnCache : wsconncache .New (s .DialWorkspaceAgent , 0 ),
157
160
AppSecurityKey : opts .AppSecurityKey ,
158
161
159
- // TODO: We need to pass some deployment values to here
160
- DisablePathApps : false ,
161
- SecureAuthCookie : false ,
162
+ DisablePathApps : opts .DisablePathApps ,
163
+ SecureAuthCookie : opts .SecureAuthCookie ,
162
164
}
163
165
164
166
// Routes
@@ -173,11 +175,10 @@ func New(opts *Options) (*Server, error) {
173
175
httpmw .ExtractRealIP (s .Options .RealIPConfig ),
174
176
httpmw .Logger (s .Logger ),
175
177
httpmw .Prometheus (s .PrometheusRegistry ),
176
- ExtractSessionTokenMW (),
177
178
178
179
// SubdomainAppMW is a middleware that handles all requests to the
179
180
// subdomain based workspace apps.
180
- s .AppServer .SubdomainAppMW (apiRateLimiter ),
181
+ s .AppServer .SubdomainAppMW (apiRateLimiter , ExtractSessionTokenMW () ),
181
182
// Build-Version is helpful for debugging.
182
183
func (next http.Handler ) http.Handler {
183
184
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -202,11 +203,15 @@ func New(opts *Options) (*Server, error) {
202
203
203
204
// Attach workspace apps routes.
204
205
r .Group (func (r chi.Router ) {
205
- r .Use (apiRateLimiter )
206
+ r .Use (
207
+ apiRateLimiter ,
208
+ ExtractSessionTokenMW (),
209
+ )
206
210
s .AppServer .Attach (r )
207
211
})
208
212
209
- // TODO: @emyrk Buildinfo and healthz routes.
213
+ r .Get ("/buildinfo" , s .buildInfo )
214
+ r .Get ("/healthz" , func (w http.ResponseWriter , r * http.Request ) { _ , _ = w .Write ([]byte ("OK" )) })
210
215
211
216
return s , nil
212
217
}
@@ -220,6 +225,17 @@ func (s *Server) DialWorkspaceAgent(id uuid.UUID) (*codersdk.WorkspaceAgentConn,
220
225
return s .SDKClient .DialWorkspaceAgent (s .ctx , id , nil )
221
226
}
222
227
228
+ func (s * Server ) buildInfo (rw http.ResponseWriter , r * http.Request ) {
229
+ httpapi .Write (r .Context (), rw , http .StatusOK , codersdk.BuildInfoResponse {
230
+ ExternalURL : buildinfo .ExternalURL (),
231
+ Version : buildinfo .Version (),
232
+ WorkspaceProxy : & codersdk.WorkspaceProxyBuildInfo {
233
+ IsWorkspaceProxy : true ,
234
+ DashboardURL : s .PrimaryAccessURL .String (),
235
+ },
236
+ })
237
+ }
238
+
223
239
type optErrors []error
224
240
225
241
func (e optErrors ) Error () string {
0 commit comments