From 28a518259ca92135d196de2b411d770d3ec9dfa9 Mon Sep 17 00:00:00 2001 From: Aaron Parker Date: Mon, 12 Oct 2026 14:41:17 +1100 Subject: [PATCH] Add staging deploy scripts and env wiring Expose `ENVIRONMENT` on `globalThis` so runtime logic can detect staging vs production. Add npm scripts for staging/production deploys and staging tailing, document the staging Worker setup in `wrangler.toml`, and add a `test:staging` command to run the test suite against the staging API endpoint. --- src/index.js | 1 + src/package.json | 5 ++++- src/wrangler.toml | 2 ++ tests/package.json | 3 ++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index e99c704..afa4594 100644 --- a/src/index.js +++ b/src/index.js @@ -535,6 +535,7 @@ export default { globalThis.LOGS_BUCKET = env.LOGS_BUCKET globalThis.REQUEST_ANALYTICS = env.REQUEST_ANALYTICS globalThis.API_TEST_USERAGENT = env.API_TEST_USERAGENT + globalThis.ENVIRONMENT = env.ENVIRONMENT const startTime = Date.now() const url = new URL(request.url) diff --git a/src/package.json b/src/package.json index eff251d..9630165 100644 --- a/src/package.json +++ b/src/package.json @@ -5,7 +5,10 @@ "main": "src/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "publish": "wrangler publish" + "publish": "wrangler publish", + "deploy:staging": "wrangler deploy --env staging", + "deploy:production": "wrangler deploy --env production", + "tail:staging": "wrangler tail --env staging" }, "repository": { "type": "git", diff --git a/src/wrangler.toml b/src/wrangler.toml index be809da..d75ff25 100644 --- a/src/wrangler.toml +++ b/src/wrangler.toml @@ -40,6 +40,8 @@ bucket_name = "evergreen-api" binding = "REQUEST_ANALYTICS" dataset = "evergreen_requests" +# Staging: https://evergreen-api-staging.stealthpuppy.workers.dev +# Shares the production EVERGREEN KV namespace (read-only usage), but logs/analytics are kept separate [env.staging] name = "evergreen-api-staging" vars = { ENVIRONMENT = "staging" } diff --git a/tests/package.json b/tests/package.json index d385f04..844e66b 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,6 +1,7 @@ { "scripts": { - "test": "mocha" + "test": "mocha", + "test:staging": "API_BASE_URL=https://evergreen-api-staging.stealthpuppy.workers.dev mocha" }, "devDependencies": { "chai": "^6.2.2",