Skip to content

Commit 3aad5a0

Browse files
fix: Add missing header and use correct endpoint host (#23982)
1 parent 6a40936 commit 3aad5a0

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

packages/data-context/src/actions/EventCollectorActions.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ interface CollectableEvent {
1010
cohort?: string
1111
}
1212

13-
const cloudEnv = (process.env.CYPRESS_INTERNAL_EVENT_COLLECTOR_ENV || 'staging') as 'development' | 'staging' | 'production'
13+
/**
14+
* Defaults to staging when doing development. To override to production for development,
15+
* explicitly set process.env.CYPRESS_INTERNAL_ENV to 'production`
16+
*/
17+
const cloudEnv = (process.env.CYPRESS_INTERNAL_EVENT_COLLECTOR_ENV || 'production') as 'development' | 'staging' | 'production'
1418

1519
export class EventCollectorActions {
1620
constructor (private ctx: DataContext) {
@@ -23,7 +27,11 @@ export class EventCollectorActions {
2327

2428
await this.ctx.util.fetch(
2529
`${dashboardUrl}/anon-collect`,
26-
{ method: 'POST', body: JSON.stringify(event) },
30+
{
31+
method: 'POST',
32+
headers: { 'Content-Type': 'application/json' },
33+
body: JSON.stringify(event),
34+
},
2735
)
2836

2937
debug(`Recorded event: %o`, event)

packages/data-context/test/unit/actions/EventCollectorActions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('EventCollectorActions', () => {
3232

3333
expect(ctx.util.fetch).to.have.been.calledOnceWith(
3434
sinon.match(/anon-collect$/), // Verify URL ends with expected 'anon-collect' path
35-
{ method: 'POST', body: '{"campaign":"abc","medium":"def","messageId":"ghi","cohort":"123"}' },
35+
{ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{"campaign":"abc","medium":"def","messageId":"ghi","cohort":"123"}' },
3636
)
3737
})
3838

scripts/gulp/gulpConstants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ declare global {
88
}
99
}
1010

11+
/**
12+
* Gulp is only used for running the application during development. At this point of starting the app,
13+
* process.env.CYPRESS_INTERNAL_ENV has not been set yet unless explicitly set on the command line. If not
14+
* set on the command line, it is set to 'development' [here](https://github.com/cypress-io/cypress/blob/a5ec234005fead97f6cfdf611abf8d9f4ad0565d/packages/server/lib/environment.js#L22)
15+
*
16+
* When running in a production build, a file is written out to set CYPRESS_INTERNAL_ENV to 'production'
17+
* [here](https://github.com/cypress-io/cypress/blob/a5ec234005fead97f6cfdf611abf8d9f4ad0565d/scripts/binary/build.ts#L176).
18+
* However, running in production will not use the code in this file.
19+
*/
20+
1121
export const DEFAULT_INTERNAL_CLOUD_ENV = process.env.CYPRESS_INTERNAL_ENV || 'production'
1222

1323
export const DEFAULT_INTERNAL_EVENT_COLLECTOR_ENV = process.env.CYPRESS_INTERNAL_ENV || 'staging'

0 commit comments

Comments
 (0)