Skip to content
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
7 changes: 5 additions & 2 deletions packages/stats-generator/src/clientSideRendered/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { spawn } from 'node:child_process'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { packagesDir } from '../constants.ts'
import { getHost } from '../serve/common.ts'
import { runBenchmark } from './run-benchmark.ts'
import type { ClientSideRenderedBenchmarkResult } from './types.ts'

const CLIENT_SIDE_RENDERED_HOST = getHost()
const CLIENT_SIDE_RENDERED_PORT = 3001

interface ClientSideRenderedFrameworkConfig {
Expand Down Expand Up @@ -85,6 +87,7 @@ async function spawnServer(
const proc = spawn('node', [scriptPath, appDir], {
env: {
...process.env,
HOST: CLIENT_SIDE_RENDERED_HOST,
NODE_ENV: 'production',
PORT: String(CLIENT_SIDE_RENDERED_PORT),
},
Expand Down Expand Up @@ -116,7 +119,7 @@ async function spawnServer(

await Promise.race([
waitForServer(
`http://localhost:${CLIENT_SIDE_RENDERED_PORT}/client-side-rendered`,
`http://${CLIENT_SIDE_RENDERED_HOST}:${CLIENT_SIDE_RENDERED_PORT}/client-side-rendered`,
),
exitPromise,
])
Expand Down Expand Up @@ -148,7 +151,7 @@ export async function runClientSideRenderedBenchmark(
`Running client-side rendered benchmark for ${config.displayName}...`,
)
return await runBenchmark(
`http://localhost:${CLIENT_SIDE_RENDERED_PORT}`,
`http://${CLIENT_SIDE_RENDERED_HOST}:${CLIENT_SIDE_RENDERED_PORT}`,
config.name,
config.displayName,
runs,
Expand Down
13 changes: 11 additions & 2 deletions packages/stats-generator/src/serve/astro.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { join } from 'node:path'
import { getPort, parseAppDir, spawnProductionServer } from './common.ts'
import {
getHost,
getPort,
parseAppDir,
spawnProductionServer,
} from './common.ts'

const appDir = parseAppDir()
const HOST = getHost()
const PORT = getPort(4321)
const entryPath = join(appDir, 'dist', 'server', 'entry.mjs')

spawnProductionServer([entryPath], appDir, { PORT: String(PORT) })
spawnProductionServer([entryPath], appDir, {
HOST,
PORT: String(PORT),
})
7 changes: 4 additions & 3 deletions packages/stats-generator/src/serve/baseline-html.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createServer } from 'node:http'
import { testData } from '../../../testdata/src/ssr.ts'
import { renderBaselineHtml } from '../baseline-html.ts'
import { getPort, registerShutdown } from './common.ts'
import { getHost, getPort, registerShutdown } from './common.ts'

const HOST = getHost()
const PORT = getPort()

const server = createServer(async (_req, res) => {
Expand All @@ -11,8 +12,8 @@ const server = createServer(async (_req, res) => {

res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' })
res.end(html)
}).listen(PORT, () => {
console.log(`Ready at http://localhost:${PORT}`)
}).listen(PORT, HOST, () => {
console.log(`Ready at http://${HOST}:${PORT}`)
})

registerShutdown(server)
4 changes: 4 additions & 0 deletions packages/stats-generator/src/serve/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export function getPort(defaultPort = 3000): number {
return Number.parseInt(process.env.PORT ?? String(defaultPort), 10)
}

export function getHost(defaultHost = '127.0.0.1'): string {
return process.env.HOST ?? defaultHost
}

export function parseAppDir(): string {
const appDir = process.argv[2]
if (!appDir) {
Expand Down
12 changes: 9 additions & 3 deletions packages/stats-generator/src/serve/next.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { createRequire } from 'node:module'
import { join } from 'node:path'
import { getPort, parseAppDir, spawnProductionServer } from './common.ts'
import {
getHost,
getPort,
parseAppDir,
spawnProductionServer,
} from './common.ts'

const appDir = parseAppDir()
const HOST = getHost()
const PORT = getPort()

const appRequire = createRequire(join(appDir, 'package.json'))
const nextBinPath = appRequire.resolve('next/dist/bin/next')

spawnProductionServer(
[nextBinPath, 'start', '--port', String(PORT), '--hostname', 'localhost'],
[nextBinPath, 'start', '--port', String(PORT), '--hostname', HOST],
appDir,
{ PORT: String(PORT) },
{ HOST, PORT: String(PORT) },
)
13 changes: 11 additions & 2 deletions packages/stats-generator/src/serve/nitro.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { join } from 'node:path'
import { getPort, parseAppDir, spawnProductionServer } from './common.ts'
import {
getHost,
getPort,
parseAppDir,
spawnProductionServer,
} from './common.ts'

const appDir = parseAppDir()
const HOST = getHost()
const PORT = getPort()
const entryPath = join(appDir, '.output', 'server', 'index.mjs')

spawnProductionServer([entryPath], appDir, { PORT: String(PORT) })
spawnProductionServer([entryPath], appDir, {
HOST,
PORT: String(PORT),
})
9 changes: 8 additions & 1 deletion packages/stats-generator/src/serve/react-router.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { createRequire } from 'node:module'
import { dirname, join } from 'node:path'
import { getPort, parseAppDir, spawnProductionServer } from './common.ts'
import {
getHost,
getPort,
parseAppDir,
spawnProductionServer,
} from './common.ts'

const appDir = parseAppDir()
const HOST = getHost()
const PORT = getPort()
const buildPath = join(appDir, 'build', 'server', 'index.js')

Expand All @@ -11,5 +17,6 @@ const servePackagePath = appRequire.resolve('@react-router/serve/package.json')
const serveBinPath = join(dirname(servePackagePath), 'bin.js')

spawnProductionServer([serveBinPath, buildPath], appDir, {
HOST,
PORT: String(PORT),
})
13 changes: 11 additions & 2 deletions packages/stats-generator/src/serve/sveltekit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { join } from 'node:path'
import { getPort, parseAppDir, spawnProductionServer } from './common.ts'
import {
getHost,
getPort,
parseAppDir,
spawnProductionServer,
} from './common.ts'

const appDir = parseAppDir()
const HOST = getHost()
const PORT = getPort()
const entryPath = join(appDir, 'build', 'index.js')

spawnProductionServer([entryPath], appDir, { PORT: String(PORT) })
spawnProductionServer([entryPath], appDir, {
HOST,
PORT: String(PORT),
})
13 changes: 11 additions & 2 deletions packages/stats-generator/src/serve/tanstack-start.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { join } from 'node:path'
import { getPort, parseAppDir, spawnProductionServer } from './common.ts'
import {
getHost,
getPort,
parseAppDir,
spawnProductionServer,
} from './common.ts'

const appDir = parseAppDir()
const HOST = getHost()
const PORT = getPort()
const entryPath = join(appDir, '.output', 'server', 'index.mjs')

spawnProductionServer([entryPath], appDir, { PORT: String(PORT) })
spawnProductionServer([entryPath], appDir, {
HOST,
PORT: String(PORT),
})
7 changes: 5 additions & 2 deletions packages/stats-generator/src/serverSideRendered/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { spawn } from 'node:child_process'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { packagesDir } from '../constants.ts'
import { getHost } from '../serve/common.ts'
import { runBenchmark } from './run-benchmark.ts'
import type { ServerSideRenderedBenchmarkResult } from './types.ts'

const SERVER_SIDE_RENDERED_HOST = getHost()
const SERVER_SIDE_RENDERED_PORT = 3002

interface ServerSideRenderedFrameworkConfig {
Expand Down Expand Up @@ -84,6 +86,7 @@ async function spawnServer(
const proc = spawn('node', [scriptPath, appDir], {
env: {
...process.env,
HOST: SERVER_SIDE_RENDERED_HOST,
NODE_ENV: 'production',
PORT: String(SERVER_SIDE_RENDERED_PORT),
},
Expand Down Expand Up @@ -115,7 +118,7 @@ async function spawnServer(

await Promise.race([
waitForServer(
`http://localhost:${SERVER_SIDE_RENDERED_PORT}/server-side-rendered`,
`http://${SERVER_SIDE_RENDERED_HOST}:${SERVER_SIDE_RENDERED_PORT}/server-side-rendered`,
),
exitPromise,
])
Expand Down Expand Up @@ -147,7 +150,7 @@ export async function runServerSideRenderedBenchmark(
`Running server side rendered benchmark for ${config.displayName}...`,
)
return await runBenchmark(
`http://localhost:${SERVER_SIDE_RENDERED_PORT}`,
`http://${SERVER_SIDE_RENDERED_HOST}:${SERVER_SIDE_RENDERED_PORT}`,
config.name,
config.displayName,
runs,
Expand Down
7 changes: 5 additions & 2 deletions packages/stats-generator/src/ssrLoad/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { spawn } from 'node:child_process'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { packagesDir } from '../constants.ts'
import { getHost } from '../serve/common.ts'
import { runLoadTest } from './run-load-test.ts'
import type { SSRLoadBenchmarkResult } from './types.ts'

const SSR_LOAD_HOST = getHost()
const SSR_LOAD_PORT = 3003
const SSR_LOAD_PATH = '/server-side-rendered'

Expand Down Expand Up @@ -100,6 +102,7 @@ async function spawnServer(
const proc = spawn('node', [scriptPath, appDir], {
env: {
...process.env,
HOST: SSR_LOAD_HOST,
NODE_ENV: 'production',
PORT: String(SSR_LOAD_PORT),
},
Expand Down Expand Up @@ -130,7 +133,7 @@ async function spawnServer(
})

await Promise.race([
waitForServer(`http://localhost:${SSR_LOAD_PORT}${SSR_LOAD_PATH}`),
waitForServer(`http://${SSR_LOAD_HOST}:${SSR_LOAD_PORT}${SSR_LOAD_PATH}`),
exitPromise,
])

Expand All @@ -152,7 +155,7 @@ export async function runSSRLoadBenchmark(
)
}

const url = `http://localhost:${SSR_LOAD_PORT}${SSR_LOAD_PATH}`
const url = `http://${SSR_LOAD_HOST}:${SSR_LOAD_PORT}${SSR_LOAD_PATH}`
console.info(`Starting server for ${config.displayName}...`)
const killServer = await spawnServer(config)

Expand Down
Loading