Skip to content

Commit

Permalink
chore: share client route
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiller1990 committed Sep 23, 2021
1 parent 20c8c5f commit 1366b69
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 43 deletions.
21 changes: 1 addition & 20 deletions packages/server/lib/routes-ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Debug from 'debug'
import { Request, Response, Router } from 'express'
import send from 'send'
import { getPathToDist } from '@packages/resolve-dist'
import { runner } from './controllers/runner'
import type { InitializeRoutes } from './routes'

const debug = Debug('cypress:server:routes-ct')
Expand All @@ -15,12 +14,7 @@ const serveChunk = (req: Request, res: Response, clientRoute: string) => {

export const createRoutesCT = ({
config,
specsStore,
nodeProxy,
getCurrentBrowser,
testingType,
getSpec,
getRemoteState,
}: InitializeRoutes) => {
const routesCt = Router()

Expand All @@ -38,26 +32,13 @@ export const createRoutesCT = ({
})
})

// enables runner-ct to make a dynamic import
const clientRoute = config.clientRoute

if (!clientRoute) {
throw Error(`clientRoute is required. Received ${clientRoute}`)
}

routesCt.get(clientRoute, (req, res) => {
debug('Serving Cypress front-end by requested URL:', req.url)

runner.serve(req, res, 'runner-ct', {
config,
testingType,
getSpec,
getCurrentBrowser,
getRemoteState,
specsStore,
})
})

// enables runner-ct to make a dynamic import
routesCt.get([
`${clientRoute}ctChunk-*`,
`${clientRoute}vendors~ctChunk-*`,
Expand Down
23 changes: 0 additions & 23 deletions packages/server/lib/routes-e2e.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import path from 'path'
import la from 'lazy-ass'
import check from 'check-more-types'
import Debug from 'debug'
import { Router } from 'express'

import AppData from './util/app_data'
import CacheBuster from './util/cache_buster'
import specController from './controllers/spec'
import reporter from './controllers/reporter'
import { runner } from './controllers/runner'
import client from './controllers/client'
import files from './controllers/files'
import type { InitializeRoutes } from './routes'
Expand All @@ -17,13 +14,8 @@ const debug = Debug('cypress:server:routes-e2e')

export const createRoutesE2E = ({
config,
specsStore,
getRemoteState,
networkProxy,
getSpec,
getCurrentBrowser,
onError,
testingType,
}: InitializeRoutes) => {
const routesE2E = Router()

Expand Down Expand Up @@ -137,20 +129,5 @@ export const createRoutesE2E = ({
res.sendFile(file, { etag: false })
})

la(check.unemptyString(config.clientRoute), 'missing client route in config', config)

routesE2E.get(`${config.clientRoute}`, (req, res) => {
debug('Serving Cypress front-end by requested URL:', req.url)

runner.serve(req, res, 'runner', {
config,
testingType,
getSpec,
getCurrentBrowser,
getRemoteState,
specsStore,
})
})

return routesE2E
}
24 changes: 24 additions & 0 deletions packages/server/lib/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type httpProxy from 'http-proxy'
import Debug from 'debug'
import { ErrorRequestHandler, Router } from 'express'

import type { SpecsStore } from './specs-store'
Expand All @@ -9,6 +10,8 @@ import xhrs from './controllers/xhrs'
import { runner } from './controllers/runner'
import { iframesController } from './controllers/iframes'

const debug = Debug('cypress:server:routes')

export interface InitializeRoutes {
specsStore: SpecsStore
config: Cfg
Expand All @@ -26,6 +29,8 @@ export const createCommonRoutes = ({
networkProxy,
testingType,
getSpec,
getCurrentBrowser,
specsStore,
getRemoteState,
nodeProxy,
}: InitializeRoutes) => {
Expand All @@ -49,6 +54,25 @@ export const createCommonRoutes = ({
}
})

const clientRoute = config.clientRoute

if (!clientRoute) {
throw Error(`clientRoute is required. Received ${clientRoute}`)
}

router.get(clientRoute, (req, res) => {
debug('Serving Cypress front-end by requested URL:', req.url)

runner.serve(req, res, testingType === 'e2e' ? 'runner' : 'runner-ct', {
config,
testingType,
getSpec,
getCurrentBrowser,
getRemoteState,
specsStore,
})
})

router.all('*', (req, res) => {
networkProxy.handleHttpRequest(req, res)
})
Expand Down

0 comments on commit 1366b69

Please sign in to comment.