diff --git a/codersdk/client.go b/codersdk/client.go index 2097225ff489c..105c8437f841b 100644 --- a/codersdk/client.go +++ b/codersdk/client.go @@ -29,9 +29,11 @@ import ( // These cookies are Coder-specific. If a new one is added or changed, the name // shouldn't be likely to conflict with any user-application set cookies. // Be sure to strip additional cookies in httpapi.StripCoderCookies! +// SessionTokenCookie represents the name of the cookie or query parameter the API key is stored in. +// NOTE: This is declared as a var so that we can override it in `develop.sh` if required. +var SessionTokenCookie = "coder_session_token" + const ( - // SessionTokenCookie represents the name of the cookie or query parameter the API key is stored in. - SessionTokenCookie = "coder_session_token" // SessionTokenHeader is the custom header to use for authentication. SessionTokenHeader = "Coder-Session-Token" // OAuth2StateCookie is the name of the cookie that stores the oauth2 state. diff --git a/scripts/build_go.sh b/scripts/build_go.sh index b3b074b183f91..e291d5fc29189 100755 --- a/scripts/build_go.sh +++ b/scripts/build_go.sh @@ -49,6 +49,7 @@ boringcrypto=${CODER_BUILD_BORINGCRYPTO:-0} dylib=0 windows_resources="${CODER_WINDOWS_RESOURCES:-0}" debug=0 +develop_in_coder="${DEVELOP_IN_CODER:-0}" bin_ident="com.coder.cli" @@ -149,6 +150,13 @@ if [[ "$debug" == 0 ]]; then ldflags+=(-s -w) fi +if [[ "$develop_in_coder" == 1 ]]; then + echo "INFO : Overriding codersdk.SessionTokenCookie as we are developing inside a Coder workspace." + ldflags+=( + -X "'github.com/coder/coder/v2/codersdk.SessionTokenCookie=dev_coder_session_token'" + ) +fi + # We use ts_omit_aws here because on Linux it prevents Tailscale from importing # github.com/aws/aws-sdk-go-v2/aws, which adds 7 MB to the binary. TS_EXTRA_SMALL="ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube" diff --git a/scripts/coder-dev.sh b/scripts/coder-dev.sh index f475a124f2c05..51c198166942b 100755 --- a/scripts/coder-dev.sh +++ b/scripts/coder-dev.sh @@ -10,6 +10,8 @@ source "${SCRIPT_DIR}/lib.sh" GOOS="$(go env GOOS)" GOARCH="$(go env GOARCH)" +CODER_AGENT_URL="${CODER_AGENT_URL:-}" +DEVELOP_IN_CODER="${DEVELOP_IN_CODER:-0}" DEBUG_DELVE="${DEBUG_DELVE:-0}" BINARY_TYPE=coder-slim if [[ ${1:-} == server ]]; then @@ -35,6 +37,10 @@ CODER_DEV_DIR="$(realpath ./.coderv2)" CODER_DELVE_DEBUG_BIN=$(realpath "./build/coder_debug_${GOOS}_${GOARCH}") popd +if [ -n "${CODER_AGENT_URL}" ]; then + DEVELOP_IN_CODER=1 +fi + case $BINARY_TYPE in coder-slim) # Ensure the coder slim binary is always up-to-date with local @@ -42,9 +48,9 @@ coder-slim) # NOTE: we send all output of `make` to /dev/null so that we do not break # scripts that read the output of this command. if [[ -t 1 ]]; then - make -j "${RELATIVE_BINARY_PATH}" + DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" make -j "${RELATIVE_BINARY_PATH}" else - make -j "${RELATIVE_BINARY_PATH}" >/dev/null 2>&1 + DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" make -j "${RELATIVE_BINARY_PATH}" >/dev/null 2>&1 fi ;; coder) diff --git a/scripts/develop.sh b/scripts/develop.sh index c9d36d19db660..a83d2e5cbd57f 100755 --- a/scripts/develop.sh +++ b/scripts/develop.sh @@ -14,6 +14,7 @@ source "${SCRIPT_DIR}/lib.sh" set -euo pipefail CODER_DEV_ACCESS_URL="${CODER_DEV_ACCESS_URL:-http://127.0.0.1:3000}" +DEVELOP_IN_CODER="${DEVELOP_IN_CODER:-0}" debug=0 DEFAULT_PASSWORD="SomeSecurePassword!" password="${CODER_DEV_ADMIN_PASSWORD:-${DEFAULT_PASSWORD}}" @@ -66,6 +67,10 @@ if [ "${CODER_BUILD_AGPL:-0}" -gt "0" ] && [ "${multi_org}" -gt "0" ]; then echo '== ERROR: cannot use both multi-organizations and APGL build.' && exit 1 fi +if [ -n "${CODER_AGENT_URL}" ]; then + DEVELOP_IN_CODER=1 +fi + # Preflight checks: ensure we have our required dependencies, and make sure nothing is listening on port 3000 or 8080 dependencies curl git go make pnpm curl --fail http://127.0.0.1:3000 >/dev/null 2>&1 && echo '== ERROR: something is listening on port 3000. Kill it and re-run this script.' && exit 1 @@ -75,7 +80,7 @@ curl --fail http://127.0.0.1:8080 >/dev/null 2>&1 && echo '== ERROR: something i # node_modules if necessary. GOOS="$(go env GOOS)" GOARCH="$(go env GOARCH)" -make -j "build/coder_${GOOS}_${GOARCH}" +DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" make -j "build/coder_${GOOS}_${GOARCH}" # Use the coder dev shim so we don't overwrite the user's existing Coder config. CODER_DEV_SHIM="${PROJECT_ROOT}/scripts/coder-dev.sh" @@ -150,7 +155,7 @@ fatal() { trap 'fatal "Script encountered an error"' ERR cdroot - DEBUG_DELVE="${debug}" start_cmd API "" "${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url "${CODER_DEV_ACCESS_URL}" --dangerous-allow-cors-requests=true --enable-terraform-debug-mode "$@" + DEBUG_DELVE="${debug}" DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" start_cmd API "" "${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url "${CODER_DEV_ACCESS_URL}" --dangerous-allow-cors-requests=true --enable-terraform-debug-mode "$@" echo '== Waiting for Coder to become ready' # Start the timeout in the background so interrupting this script diff --git a/site/src/api/api.ts b/site/src/api/api.ts index 9a46c40217091..cd70bfaf00600 100644 --- a/site/src/api/api.ts +++ b/site/src/api/api.ts @@ -107,6 +107,13 @@ const getMissingParameters = ( return missingParameters; }; +/** + * Originally from codersdk/client.go. + * The below declaration is required to stop Knip from complaining. + * @public + */ +export const SessionTokenCookie = "coder_session_token"; + /** * @param agentId * @returns {OneWayWebSocket} A OneWayWebSocket that emits Server-Sent Events. diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index 379cd21e03d4e..421cf0872a6b9 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -2700,9 +2700,6 @@ export interface SessionLifetime { readonly max_admin_token_lifetime?: number; } -// From codersdk/client.go -export const SessionTokenCookie = "coder_session_token"; - // From codersdk/client.go export const SessionTokenHeader = "Coder-Session-Token"; diff --git a/site/vite.config.mts b/site/vite.config.mts index d386499e50ed0..e6a30aa71744e 100644 --- a/site/vite.config.mts +++ b/site/vite.config.mts @@ -116,7 +116,7 @@ export default defineConfig({ secure: process.env.NODE_ENV === "production", }, }, - allowedHosts: [".coder"], + allowedHosts: [".coder", ".dev.coder.com"], }, resolve: { alias: { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy