@@ -6,6 +6,7 @@ import send from 'send'
66import { getPathToDist } from '@packages/resolve-dist'
77import type { InitializeRoutes } from './routes'
88import { fs } from './util/fs'
9+ import type { DataContextShell } from '@packages/data-context/src/DataContextShell'
910
1011const 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