Skip to content

Commit 1be7674

Browse files
authoredMar 1, 2025··
chore(cli): run app dev command on different port (#8769)
1 parent e50b1cc commit 1be7674

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'
2+
3+
import {startDevServer} from '../../server/devServer'
4+
import {gracefulServerDeath} from '../../util/servers'
5+
import {getDevServerConfig, type StartDevServerCommandFlags} from '../dev/devAction'
6+
7+
export default async function startAppDevServer(
8+
args: CliCommandArguments<StartDevServerCommandFlags>,
9+
context: CliCommandContext,
10+
): Promise<void> {
11+
const flags = args.extOptions
12+
const {output, workDir, cliConfig} = context
13+
14+
// Try to load CLI configuration from sanity.cli.(js|ts)
15+
const config = getDevServerConfig({
16+
flags: {
17+
...flags,
18+
port: flags.port || '3334',
19+
},
20+
workDir,
21+
cliConfig,
22+
output,
23+
})
24+
25+
try {
26+
await startDevServer(config)
27+
} catch (err) {
28+
gracefulServerDeath('dev', config.httpHost, config.httpPort, err)
29+
}
30+
}

‎packages/sanity/src/_internal/cli/actions/dev/devAction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default async function startSanityDevServer(
4646
}
4747
}
4848

49-
function getDevServerConfig({
49+
export function getDevServerConfig({
5050
flags,
5151
workDir,
5252
cliConfig,

‎packages/sanity/src/_internal/cli/commands/app/devCommand.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Notes
1111
Changing the hostname or port number might require a new entry to the CORS-origins allow list.
1212
1313
Options
14-
--port <port> TCP port to start server on. [default: 3333]
14+
--port <port> TCP port to start server on. [default: 3334]
1515
--host <host> The local network interface at which to listen. [default: "127.0.0.1"]
1616
1717
Examples
@@ -45,12 +45,12 @@ export async function getDevAction(): Promise<
4545
// NOTE: this `if` statement is not included in the output bundle
4646
if (__DEV__) {
4747
// eslint-disable-next-line import/extensions,@typescript-eslint/consistent-type-imports
48-
const mod: typeof import('../../actions/dev/devAction') = require('../../actions/dev/devAction.ts')
48+
const mod: typeof import('../../actions/app/devAction') = require('../../actions/app/devAction.ts')
4949

5050
return mod.default
5151
}
5252

53-
const mod = await import('../../actions/dev/devAction')
53+
const mod = await import('../../actions/app/devAction')
5454

5555
return mod.default
5656
}

0 commit comments

Comments
 (0)
Please sign in to comment.