diff --git a/src/core/utils/net.ts b/src/core/utils/net.ts index 1af48591..8dfe694d 100644 --- a/src/core/utils/net.ts +++ b/src/core/utils/net.ts @@ -103,7 +103,7 @@ export async function validateDevServerConfig(url: string | undefined, timeout: const resolvedPortNumber = await isAcceptingTcpConnections({ port, host: hostname }); if (resolvedPortNumber !== 0) { const spinner = ora(); - let waitOnOneOfResources = hostname === "localhost" ? [`tcp:127.0.0.1:${port}`, `tcp:localhost:${port}`] : [`tcp:${hostname}:${port}`]; + const waitOnOneOfResources = hostname === "localhost" ? [`tcp:127.0.0.1:${port}`, `tcp:[::1]:${port}`] : [`tcp:${hostname}:${port}`]; spinner.start(`Waiting for ${chalk.green(url)} to be ready`); let promises = waitOnOneOfResources.map((resource) => { @@ -130,7 +130,7 @@ export async function validateDevServerConfig(url: string | undefined, timeout: try { await Promise.any(promises); - spinner.succeed(`${url} validated successfully`); + spinner.succeed(`Connected to ${url} successfully`); spinner.clear(); } catch { spinner.fail(); diff --git a/src/msha/middlewares/request.middleware.ts b/src/msha/middlewares/request.middleware.ts index 91257791..0f05fe53 100644 --- a/src/msha/middlewares/request.middleware.ts +++ b/src/msha/middlewares/request.middleware.ts @@ -9,8 +9,6 @@ import serveStatic from "serve-static"; import { DEFAULT_CONFIG } from "../../config"; import { findSWAConfigFile, logger, logRequest } from "../../core"; import { AUTH_STATUS, CUSTOM_URL_SCHEME, IS_APP_DEV_SERVER, SWA_PUBLIC_DIR } from "../../core/constants"; -import { parseUrl } from "../../core/utils/net"; -import waitOn from "wait-on"; import { getAuthBlockResponse, handleAuthRequest, isAuthRequest, isLoginRequest, isLogoutRequest } from "../handlers/auth.handler"; import { isDataApiRequest } from "../handlers/dab.handler"; import { handleErrorPage } from "../handlers/error-page.handler"; @@ -69,7 +67,7 @@ export async function handleUserConfig(appLocation: string | undefined): Promise * @param proxyApp An `http-proxy` instance. * @param target The root folder of the static app (ie. `output_location`). Or, the HTTP host target, if connecting to a dev server, or */ -async function serveStaticOrProxyResponse(req: http.IncomingMessage, res: http.ServerResponse, proxyApp: httpProxy, target: string | undefined) { +function serveStaticOrProxyResponse(req: http.IncomingMessage, res: http.ServerResponse, proxyApp: httpProxy, target: string | undefined) { if ([301, 302].includes(res.statusCode)) { res.end(); return; @@ -104,36 +102,6 @@ async function serveStaticOrProxyResponse(req: http.IncomingMessage, res: http.S let { protocol, hostname, port } = parseUrl(target); - if (hostname === "localhost") { - let waitOnOneOfResources = [`tcp:127.0.0.1:${port}`, `tcp:localhost:${port}`]; - let promises = waitOnOneOfResources.map((resource) => { - return waitOn({ - resources: [resource], - interval: 100, // poll interval in ms, default 250ms - simultaneous: 1, // limit to 1 connection per resource at a time - timeout: 60000, // timeout in ms, default Infinity - strictSSL: false, - verbose: false, // force disable verbose logs even if SWA_CLI_DEBUG is enabled - }) - .then(() => { - logger.silly(`Connected to ${resource} successfully`); - return resource; - }) - .catch((err) => { - logger.silly(`Could not connect to ${resource}`); - throw err; - }); - }); - - try { - const availableUrl = await Promise.any(promises); - logger.silly(`${target} validated successfully`); - target = protocol + "//" + availableUrl.slice(4); - } catch { - logger.error(`Could not connect to "${target}". Is the server up and running?`); - } - } - proxyApp.web( req, res, @@ -243,7 +211,7 @@ export async function requestMiddleware( if (isWebsocketRequest(req)) { logger.silly(`websocket request detected`); - return await serveStaticOrProxyResponse(req, res, proxyApp, DEFAULT_CONFIG.outputLocation); + return serveStaticOrProxyResponse(req, res, proxyApp, DEFAULT_CONFIG.outputLocation); } let target = DEFAULT_CONFIG.outputLocation; @@ -258,7 +226,7 @@ export async function requestMiddleware( logger.silly(` - ${statusCodeToServe} code detected. Exit`); handleErrorPage(req, res, statusCodeToServe, userConfig?.responseOverrides); - return await serveStaticOrProxyResponse(req, res, proxyApp, target); + return serveStaticOrProxyResponse(req, res, proxyApp, target); } } @@ -329,6 +297,6 @@ export async function requestMiddleware( logger.silly(` - url: ${chalk.yellow(req.url)}`); logger.silly(` - target: ${chalk.yellow(target)}`); - await serveStaticOrProxyResponse(req, res, proxyApp, target); + serveStaticOrProxyResponse(req, res, proxyApp, target); } }