Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(server): share client route #18215

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 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 @@ -44,19 +38,6 @@ export const createRoutesCT = ({
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-*`,
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