Skip to content

Commit 17f9b00

Browse files
committed
Create workspace proxy context
1 parent 9b598e8 commit 17f9b00

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

enterprise/coderd/workspaceproxy.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net/http"
99
"net/url"
10+
"strings"
1011
"time"
1112

1213
"github.com/google/uuid"
@@ -156,6 +157,20 @@ func (api *API) postWorkspaceProxy(rw http.ResponseWriter, r *http.Request) {
156157
return
157158
}
158159

160+
if strings.ToLower(req.Name) == "primary" {
161+
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
162+
Message: `The name "primary" is reserved for the primary region.`,
163+
Detail: "Cannot name a workspace proxy 'primary'.",
164+
Validations: []codersdk.ValidationError{
165+
{
166+
Field: "name",
167+
Detail: "Reserved name",
168+
},
169+
},
170+
})
171+
return
172+
}
173+
159174
id := uuid.New()
160175
secret, err := cryptorand.HexString(64)
161176
if err != nil {

site/src/hooks/usePreferredProxy.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
import { Region } from "api/typesGenerated"
22
import { useDashboard } from "components/Dashboard/DashboardProvider"
33

4-
export const usePreferredProxy = (): Region | undefined => {
4+
/*
5+
* PreferredProxy is stored in local storage. This contains the information
6+
* required to connect to a workspace via a proxy.
7+
*/
8+
export interface PreferredProxy {
9+
// Regions is a list of all the regions returned by coderd.
10+
Regions: Region[]
11+
// SelectedRegion is the region the user has selected.
12+
SelectedRegion: Region
13+
// PreferredPathAppURL is the URL of the proxy or it is the empty string
14+
// to indicte using relative paths. To add a path to this:
15+
// PreferredPathAppURL + "/path/to/app"
16+
PreferredPathAppURL: string
17+
// PreferredWildcardHostname is a hostname that includes a wildcard.
18+
// TODO: If the preferred proxy does not have this set, should we default to'
19+
// the primary's?
20+
// Example: "*.example.com"
21+
PreferredWildcardHostname: string
22+
}
23+
24+
export const usePreferredProxy = (): PreferredProxy | undefined => {
525
const dashboard = useDashboard()
626
// Only use preferred proxy if the user has the moons experiment enabled
727
if (!dashboard?.experiments.includes("moons")) {

0 commit comments

Comments
 (0)