Skip to content

Commit

Permalink
improve port handling (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc authored Feb 27, 2023
1 parent bbee3a3 commit 38b7483
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion executor/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
],
"main": "chopsticks_executor.js",
"types": "chopsticks_executor.d.ts"
}
}
5 changes: 3 additions & 2 deletions packages/chopsticks/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { isUrl } from './utils'
import { runBlock } from './run-block'

const processConfig = async (path: string) => {
let file
let file: string
if (isUrl(path)) {
file = await axios.get(path).then((x) => x.data)
} else {
Expand All @@ -26,8 +26,9 @@ const processConfig = async (path: string) => {

const processArgv = async (argv: any) => {
if (argv.config) {
return { ...(await processConfig(argv.config)), ...argv }
argv = { ...(await processConfig(argv.config)), ...argv }
}
argv.port = argv.port ?? (process.env.PORT ? Number(process.env.PORT) : 8000)
return argv
}

Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const createServer = async (handler: Handler, port?: number) => {
let wss: WebSocketServer | undefined
let listenPort: number | undefined
for (let i = 0; i < 5; i++) {
const preferPort = (port || 0) + i
const preferPort = (port ?? 0) > 0 ? (port ?? 0) + i : 0
logger.debug('Try starting on port %d', preferPort)
const [maybeWss, maybeListenPort] = await createWS(preferPort)
if (maybeWss && maybeListenPort) {
Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/setup-with-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { setup } from './setup'

export const setupWithServer = async (argv: Config) => {
const context = await setup(argv)
const port = argv.port || Number(process.env.PORT) || 8000
const port = argv.port ?? 8000

if (argv.genesis) {
// mine 1st block when starting from genesis to set some mock validation data
Expand Down

0 comments on commit 38b7483

Please sign in to comment.