@@ -249,6 +249,41 @@ type apiHost struct {
249
249
rawURL * url.URL
250
250
}
251
251
252
+ // newLocalhostHost creates a new apiHost for localhost, which is used for development purposes.
253
+ func newLocalhostHost (hostname string ) (apiHost , error ) {
254
+ u , err := url .Parse (hostname )
255
+ if err != nil {
256
+ return apiHost {}, fmt .Errorf ("failed to parse localhost URL: %w" , err )
257
+ }
258
+
259
+ restURL , err := url .Parse (fmt .Sprintf ("%s://api.%s/" , u .Scheme , u .Hostname ()))
260
+ if err != nil {
261
+ return apiHost {}, fmt .Errorf ("failed to parse localhost REST URL: %w" , err )
262
+ }
263
+
264
+ gqlURL , err := url .Parse (fmt .Sprintf ("%s://api.%s/graphql" , u .Scheme , u .Hostname ()))
265
+ if err != nil {
266
+ return apiHost {}, fmt .Errorf ("failed to parse localhost GraphQL URL: %w" , err )
267
+ }
268
+
269
+ uploadURL , err := url .Parse (fmt .Sprintf ("%s://uploads.%s" , u .Scheme , u .Hostname ()))
270
+ if err != nil {
271
+ return apiHost {}, fmt .Errorf ("failed to parse localhost Upload URL: %w" , err )
272
+ }
273
+
274
+ rawURL , err := url .Parse (fmt .Sprintf ("%s://raw.%s/" , u .Scheme , u .Hostname ()))
275
+ if err != nil {
276
+ return apiHost {}, fmt .Errorf ("failed to parse localhost Raw URL: %w" , err )
277
+ }
278
+
279
+ return apiHost {
280
+ baseRESTURL : restURL ,
281
+ graphqlURL : gqlURL ,
282
+ uploadURL : uploadURL ,
283
+ rawURL : rawURL ,
284
+ }, nil
285
+ }
286
+
252
287
func newDotcomHost () (apiHost , error ) {
253
288
baseRestURL , err := url .Parse ("https://api.github.com/" )
254
289
if err != nil {
@@ -365,6 +400,10 @@ func parseAPIHost(s string) (apiHost, error) {
365
400
return apiHost {}, fmt .Errorf ("host must have a scheme (http or https): %s" , s )
366
401
}
367
402
403
+ if strings .HasSuffix (u .Hostname (), "localhost" ) {
404
+ return newLocalhostHost (s )
405
+ }
406
+
368
407
if strings .HasSuffix (u .Hostname (), "github.com" ) {
369
408
return newDotcomHost ()
370
409
}
0 commit comments