Skip to content

Commit f13c63e

Browse files
committed
cleanup __CYPRESS_GRAPHQL_PORT injection
1 parent 1da2ee4 commit f13c63e

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

packages/frontend-shared/src/graphql/urqlClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function makeUrqlClient (target: 'launchpad' | 'app'): Client {
4343
gqlPort = GQL_PORT_MATCH[1]
4444
} else {
4545
// @ts-ignore
46-
gqlPort = window.__CYPRESS_GRAPHQL_PORT
46+
gqlPort = window.__CYPRESS_GRAPHQL_PORT__
4747
}
4848

4949
if (!gqlPort) {

packages/server/lib/routes-ct.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import send from 'send'
66
import { getPathToDist } from '@packages/resolve-dist'
77
import type { InitializeRoutes } from './routes'
88
import { fs } from './util/fs'
9+
import type { DataContextShell } from '@packages/data-context/src/DataContextShell'
910

1011
const debug = Debug('cypress:server:routes-ct')
1112

@@ -34,25 +35,21 @@ export const createRoutesCT = ({
3435
})
3536

3637
proxyIndex.on('proxyRes', function (proxyRes, _req, _res) {
37-
if ((_req as Request).params[0] === '') {
38-
const body: any[] = []
38+
const body: any[] = []
3939

40-
proxyRes.on('data', function (chunk) {
41-
let chunkData = String(chunk)
40+
proxyRes.on('data', function (chunk) {
41+
let chunkData = String(chunk)
4242

43-
if (chunkData.includes('<head>')) {
44-
chunkData = chunkData.replace('<body>', `<body><script>window.__CYPRESS_GRAPHQL_PORT = ${JSON.stringify(ctx.gqlServerPort)};</script>\n`)
45-
}
43+
if (chunkData.includes('<head>')) {
44+
chunkData = chunkData.replace('<body>', replaceBody(ctx))
45+
}
4646

47-
body.push(chunkData)
48-
})
47+
body.push(chunkData)
48+
})
4949

50-
proxyRes.on('end', function () {
51-
(_res as Response).send(body.join(''))
52-
})
53-
} else {
54-
proxyRes.pipe(_res)
55-
}
50+
proxyRes.on('end', function () {
51+
(_res as Response).send(body.join(''))
52+
})
5653
})
5754

5855
// TODO: can namespace this onto a "unified" route like __app-unified__
@@ -71,7 +68,7 @@ export const createRoutesCT = ({
7168
if (req.params[0] === '') {
7269
return fs.readFile(pathToFile, 'utf8')
7370
.then((file) => {
74-
res.send(file.replace('<div id="app">', '<script>window.__CYPRESS_GRAPHQL_PORT = 1234</script><div id="app">'))
71+
res.send(file.replace('<body>', replaceBody(ctx)))
7572
})
7673
}
7774

@@ -160,3 +157,7 @@ export const createRoutesCT = ({
160157

161158
return routesCt
162159
}
160+
161+
function replaceBody (ctx: DataContextShell) {
162+
return `<body><script>window.__CYPRESS_GRAPHQL_PORT__ = ${JSON.stringify(ctx.gqlServerPort)};</script>\n`
163+
}

0 commit comments

Comments
 (0)