From 350c904e249efe60e72dd55e5a117a48ae06a530 Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Thu, 1 Feb 2024 15:50:59 +0000 Subject: [PATCH] fix(server): spelling, fix deploy handler imports, dedupe server builder (#9949) Follow up to https://github.com/redwoodjs/redwood/pull/9948; missed a few things at the end there: - misspelled "description" in a test mock - the server file and both server handlers take the same options, so I deduped them - related, I wasn't passing apiRootPath through to the server file handler - I incorrectly accessed `.handler` on `apiServerHandler` in flightcontrol and render --- .vscode/settings.json | 1 + .../cli/src/commands/__tests__/serve.test.js | 4 +-- .../cli/src/commands/deploy/flightcontrol.js | 2 +- packages/cli/src/commands/deploy/render.js | 2 +- packages/cli/src/commands/serve.js | 31 +------------------ packages/cli/src/commands/serveHandler.js | 2 +- 6 files changed, 7 insertions(+), 35 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 26702c59a1f0..f26ebb65101c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,6 +22,7 @@ "typescript.tsdk": "node_modules/typescript/lib", "peacock.color": "#b85833", "cSpell.words": [ + "execa", "Fastify", "pino", "redwoodjs", diff --git a/packages/cli/src/commands/__tests__/serve.test.js b/packages/cli/src/commands/__tests__/serve.test.js index 54f8c24c20d9..78df9d19575d 100644 --- a/packages/cli/src/commands/__tests__/serve.test.js +++ b/packages/cli/src/commands/__tests__/serve.test.js @@ -52,7 +52,7 @@ vi.mock('fs-extra', async (importOriginal) => { vi.mock('@redwoodjs/api-server/dist/apiCLIConfig', async (importOriginal) => { const originalAPICLIConfig = await importOriginal() return { - description: originalAPICLIConfig.desciption, + description: originalAPICLIConfig.description, builder: originalAPICLIConfig.builder, handler: vi.fn(), } @@ -60,7 +60,7 @@ vi.mock('@redwoodjs/api-server/dist/apiCLIConfig', async (importOriginal) => { vi.mock('@redwoodjs/api-server/dist/bothCLIConfig', async (importOriginal) => { const originalBothCLIConfig = await importOriginal() return { - description: originalBothCLIConfig.desciption, + description: originalBothCLIConfig.description, builder: originalBothCLIConfig.builder, handler: vi.fn(), } diff --git a/packages/cli/src/commands/deploy/flightcontrol.js b/packages/cli/src/commands/deploy/flightcontrol.js index 6ffa41e95fcd..8179d3bc4f0a 100644 --- a/packages/cli/src/commands/deploy/flightcontrol.js +++ b/packages/cli/src/commands/deploy/flightcontrol.js @@ -65,7 +65,7 @@ export const handler = async ({ side, serve, prisma, dm: dataMigrate }) => { async function runApiCommands() { if (serve) { console.log('\nStarting api...') - await apiServerHandler.handler({ + await apiServerHandler({ port: getConfig().api?.port || 8911, apiRootPath: '/', }) diff --git a/packages/cli/src/commands/deploy/render.js b/packages/cli/src/commands/deploy/render.js index 01eceb01535b..05a9d1850d5e 100644 --- a/packages/cli/src/commands/deploy/render.js +++ b/packages/cli/src/commands/deploy/render.js @@ -70,7 +70,7 @@ export const handler = async ({ side, prisma, dm: dataMigrate }) => { execaConfig ) dataMigrate && execa.sync('yarn rw dataMigrate up', execaConfig) - await apiServerHandler.handler({ + await apiServerHandler({ port: getConfig().api?.port || 8911, apiRootPath: '/', }) diff --git a/packages/cli/src/commands/serve.js b/packages/cli/src/commands/serve.js index 0aaf99e3ed0d..f0d5f84b7a83 100644 --- a/packages/cli/src/commands/serve.js +++ b/packages/cli/src/commands/serve.js @@ -25,36 +25,7 @@ export const builder = async (yargs) => { .command({ command: '$0', description: bothServerCLIConfig.description, - builder: (yargs) => { - if (hasServerFile()) { - yargs.options({ - webPort: { - description: 'The port for the web server to listen on', - type: 'number', - alias: ['web-port'], - }, - webHost: { - description: - "The host for the web server to listen on. Note that you most likely want this to be '0.0.0.0' in production", - type: 'string', - alias: ['web-host'], - }, - apiPort: { - description: 'The port for the api server to listen on', - type: 'number', - alias: ['api-port'], - }, - apiHost: { - description: - "The host for the api server to listen on. Note that you most likely want this to be '0.0.0.0' in production", - type: 'string', - alias: ['api-host'], - }, - }) - } - - bothServerCLIConfig.builder(yargs) - }, + builder: bothServerCLIConfig.builder(yargs), handler: async (argv) => { recordTelemetryAttributes({ command: 'serve', diff --git a/packages/cli/src/commands/serveHandler.js b/packages/cli/src/commands/serveHandler.js index 1cd6f0e88969..301fe8b24861 100644 --- a/packages/cli/src/commands/serveHandler.js +++ b/packages/cli/src/commands/serveHandler.js @@ -34,7 +34,7 @@ export const bothServerFileHandler = async (options) => { name: 'api', command: `yarn node ${path.join('dist', 'server.js')} --port ${ options.apiPort - } --host ${options.apiHost}`, + } --host ${options.apiHost} --api-root-path ${options.apiRootPath}`, cwd: getPaths().api.base, prefixColor: 'cyan', },