8000 Consider adding a CLI tool for srvx · Issue #90 · h3js/srvx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Consider adding a CLI tool for srvx #90
Open
@dahlia

Description

@dahlia

Describe the feature

Summary

I'd like to suggest adding a command-line interface (CLI) tool for srvx that would allow developers to start HTTP servers directly from the command line, similar to how deno serve and bun run work.

Motivation

Currently, srvx provides an excellent unified API for creating HTTP servers across different JavaScript runtimes. However, developers need to create separate script files and use runtime-specific commands to start servers, which can create some friction in the development workflow.

Current workflow:

# Create a server file
echo 'import { serve } from "srvx"; serve({ fetch: () => new Response("Hello!") });' > server.js

# Run with different commands per runtime
node                 server.js
deno run --allow-net server.js  
bun  run             server.js

Proposed workflow:

# Could potentially just run the handler file directly
npx          srvx main.js
deno run npm:srvx main.js
bunx         srvx main.js

This might bring srvx's developer experience closer to Deno and Bun's CLI tools while maintaining runtime universality.

Possible API

Basic usage

srvx main.js                    # Start server with default settings
srvx --port=3000 main.js        # Specify port
srvx --host=0.0.0.0 main.js     # Specify host

Optional enhancements

srvx --import=tsx main.ts       # TypeScript support (if feasible)
srvx --dev main.js              # Watch mode (future consideration)

Potential file formats

The CLI could potentially support multiple export patterns:

Standard export default

// main.js
export default {
  fetch(request) {
    return new Response("Hello from srvx!");
  }
}

With configuration

// main.js
export default {
  port: 3000,
  host: 'localhost',
  fetch(request) {
    return new Response("Configured server!");
  }
}

Potential benefits

  1. Improved DX: Could eliminate boilerplate and simplify server startup
  2. Consistency: Might provide uniform experience across all supported runtimes
  3. Rapid prototyping: Could enable quicker server creation and testing
  4. Familiar patterns: Would align with Deno/Bun CLI conventions
  5. TypeScript support: Potential for direct .ts file execution without compilation step

Additional considerations

  • Runtime compatibility: Ideally would work consistently across Node.js, Deno, and Bun
  • Future enhancements: TypeScript support and development features like watch mode could be valuable additions once the basic CLI is established

I think this feature could significantly enhance srvx's adoption and developer experience. I'd be happy to help with the implementation if there's interest from the maintainers!

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0