Repository: gatsbyjs/gatsby
File: packages/gatsby/src/commands/develop.ts (TypeScript)

Code before:
    }
    this.process.on(`message`, callback)
  }
  onExit(
    callback: (code: number | null, signal: NodeJS.Signals | null) => void
  ): void {
    if (!this.process) {
      throw new Error(`Trying to attach exit handler before process starter`)
    }
    this.process.on(`exit`, callback)
  }
}

let isRestarting

// checks if a string is a valid ip
const REGEX_IP = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/

module.exports = async (program: IProgram): Promise<void> => {
  const developProcessPath = slash(require.resolve(`./develop-process`))
  // Run the actual develop server on a random port, and the proxy on the program port
  // which users will access
  const proxyPort = program.port
  const debugInfo = getDebugInfo(program)
  const [statusServerPort, developPort] = await Promise.all([
    getRandomPort(program.internalStatusPort),
    getRandomPort(),
  ])

  // In order to enable custom ssl, --cert-file --key-file and -https flags must all be
  // used together
  if ((program[`cert-file`] || program[`key-file`]) && !program.https) {
    reporter.panic(
      `for custom ssl --https, --cert-file, and --key-file must be used together`
    )
  }

  // Check if https is enabled, then create or get SSL cert.
  // Certs are named 'devcert' and issued to the host.
  // NOTE(@mxstbr): We mutate program.ssl _after_ passing it
  // to the develop process controllable script above because
  // that would mean we double SSL browser => proxy => server
  if (program.https) {
    const sslHost =
      program.host === `0.0.0.0` || program.host === `::`
        ? `localhost`
        : program.host

    if (REGEX_IP.test(sslHost)) {
      reporter.panic(
        `You're trying to generate a ssl certificate for an IP (${sslHost}). Please use a hostname instead.`

Review comment (suggestion):
Rather than a cli option, let's go with just an internal env flag. We can copy paste your description as a comment here.

```suggestion
    // INTERNAL_STATUS_PORT allows for setting the websocket port used for monitoring when the browser should 
    // prompt the user to restart the develop process. This port is randomized by default and in most cases should
    // never be required to configure. It is exposed for environments where port access needs to be explicit, such as
    // with Docker. As the port is meant for internal usage only, any attempt to interface with features it exposes via
    // third-party software is not supported.
    getRandomPort(process.env.INTERNAL_STATUS_PORT),
```

Code after:
    }
    this.process.on(`message`, callback)
  }
  onExit(
    callback: (code: number | null, signal: NodeJS.Signals | null) => void
  ): void {
    if (!this.process) {
      throw new Error(`Trying to attach exit handler before process starter`)
    }
    this.process.on(`exit`, callback)
  }
}

let isRestarting

// checks if a string is a valid ip
const REGEX_IP = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/

module.exports = async (program: IProgram): Promise<void> => {
  const developProcessPath = slash(require.resolve(`./develop-process`))
  // Run the actual develop server on a random port, and the proxy on the program port
  // which users will access
  const proxyPort = program.port
  const debugInfo = getDebugInfo(program)

  // INTERNAL_STATUS_PORT allows for setting the websocket port used for monitoring
  // when the browser should prompt the user to restart the develop process.
  // This port is randomized by default and in most cases should never be required to configure.
  // It is exposed for environments where port access needs to be explicit, such as with Docker.
  // As the port is meant for internal usage only, any attempt to interface with features
  // it exposes via third-party software is not supported.
  const [statusServerPort, developPort] = await Promise.all([
    getRandomPort(process.env.INTERNAL_STATUS_PORT),
    getRandomPort(),
  ])

  // In order to enable custom ssl, --cert-file --key-file and -https flags must all be
  // used together
  if ((program[`cert-file`] || program[`key-file`]) && !program.https) {
    reporter.panic(
      `for custom ssl --https, --cert-file, and --key-file must be used together`
    )
  }

  // Check if https is enabled, then create or get SSL cert.
  // Certs are named 'devcert' and issued to the host.
  // NOTE(@mxstbr): We mutate program.ssl _after_ passing it
  // to the develop process controllable script above because
  // that would mean we double SSL browser => proxy => server
  if (program.https) {
    const sslHost =