Skip to content

[Bug] URL validation rejects valid network hostnames #1014

@vaddisrinivas

Description

@vaddisrinivas

Search before asking

  • 我在 issues 列表中搜索,没有找到类似的内容。
    I searched in the issues and found nothing similar.

Pake version

3.1.1

System version

macOS 14

Node.js version

22.2.0

Minimal reproduce step

  1. Ensure a network hostname (e.g., gateway or pihole) is resolvable via system DNS or /etc/hosts
  2. Attempt to build a pake app using the CLI: pake http://gateway --name GatewayApp
  3. Observe the error: command-argument value 'http://gateway' is invalid for argument 'url'. Your url "http://gateway" is invalid

What did you expect to see?

Pake should accept any hostname that the system can resolve, including:

  • Network hostnames without TLD (e.g., gateway, router, nas)
  • mDNS addresses (e.g., printer.local)
  • Docker container names (e.g., web-server)
  • Kubernetes service names (e.g., api-service)
  • Any syntactically valid URL that follows web standards

The CLI should proceed with building the app for the specified hostname.

What did you see instead?

The CLI rejects the hostname with a validation error: "Your url "http://gateway" is invalid", blocking the build completely.

This happens even when the hostname is perfectly valid and resolvable by the system.

Anything else?

Root Cause:
The issue is in bin/utils/url.ts in the normalizeUrl function. It uses the is-url package which has overly restrictive validation rules that only accept localhost or hostnames with traditional TLDs.

Proposed Solution:
Replace the is-url dependency with JavaScript's built-in URL constructor:

// Current problematic code
if (isUrl(urlWithProtocol)) {
  return urlWithProtocol;
}

// Proposed fix
try {
  new URL(urlWithProtocol);
  return urlWithProtocol;
} catch (err) {
  throw new Error(`Your url "${urlWithProtocol}" is invalid: ${(err as Error).message}`);
}

### Are you willing to submit a PR?

- [x] I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions