Skip to content

Commit

Permalink
fix(server): spelling, fix deploy handler imports, dedupe server buil…
Browse files Browse the repository at this point in the history
…der (#9949)

Follow up to #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
  • Loading branch information
jtoar committed Feb 1, 2024
1 parent 032a766 commit 350c904
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 35 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"typescript.tsdk": "node_modules/typescript/lib",
"peacock.color": "#b85833",
"cSpell.words": [
"execa",
"Fastify",
"pino",
"redwoodjs",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/__tests__/serve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ 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(),
}
})
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(),
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deploy/flightcontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '/',
})
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deploy/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '/',
})
Expand Down
31 changes: 1 addition & 30 deletions packages/cli/src/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/serveHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down

0 comments on commit 350c904

Please sign in to comment.