diff --git a/packages/server/lib/routes-ct.ts b/packages/server/lib/routes-ct.ts index 820a7c005c41..36a563f97854 100644 --- a/packages/server/lib/routes-ct.ts +++ b/packages/server/lib/routes-ct.ts @@ -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') @@ -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() @@ -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-*`, diff --git a/packages/server/lib/routes-e2e.ts b/packages/server/lib/routes-e2e.ts index 06252524b0a6..c358131a1c62 100644 --- a/packages/server/lib/routes-e2e.ts +++ b/packages/server/lib/routes-e2e.ts @@ -1,6 +1,4 @@ import path from 'path' -import la from 'lazy-ass' -import check from 'check-more-types' import Debug from 'debug' import { Router } from 'express' @@ -8,7 +6,6 @@ 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' @@ -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() @@ -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 } diff --git a/packages/server/lib/routes.ts b/packages/server/lib/routes.ts index 48bf6d57dca0..96afe4c83fe4 100644 --- a/packages/server/lib/routes.ts +++ b/packages/server/lib/routes.ts @@ -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' @@ -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 @@ -26,6 +29,8 @@ export const createCommonRoutes = ({ networkProxy, testingType, getSpec, + getCurrentBrowser, + specsStore, getRemoteState, nodeProxy, }: InitializeRoutes) => { @@ -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) })