Module: Portless::Frameworks
- Defined in:
- lib/portless/frameworks.rb
Overview
Most servers (Rails/puma, Express, Nuxt, …) honour the PORT env we inject. A handful ignore it and need an explicit --port flag; some also need --host so they bind loopback where the proxy expects them. We see through package runners (npx/bunx/pnpm dlx/…). Mirrors portless's injectFrameworkFlags.
Constant Summary collapse
- NEEDS_PORT =
basename => needs --strictPort
{ "vite" => true, "vp" => true, "react-router" => true, "rsbuild" => false, "astro" => false, "ng" => false, "react-native" => false, "expo" => false }.freeze
- RUNNERS =
%w[npx bunx pnpm yarn dlx exec run].freeze
Class Method Summary collapse
-
.framework_basename(command) ⇒ Object
The first argument that's a real command, seeing past package runners and their subcommands (npx vite, pnpm exec astro, …).
- .inject(command, port) ⇒ Object
Class Method Details
.framework_basename(command) ⇒ Object
The first argument that's a real command, seeing past package runners and their subcommands (npx vite, pnpm exec astro, …).
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/portless/frameworks.rb', line 31 def framework_basename(command) command.each do |arg| next if arg.to_s.start_with?("-") base = File.basename(arg.to_s) next if RUNNERS.include?(base) return base end "" end |
.inject(command, port) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/portless/frameworks.rb', line 19 def inject(command, port) base = framework_basename(command) return command unless NEEDS_PORT.key?(base) flags = [ "--port", port.to_s ] flags << "--strictPort" if NEEDS_PORT.fetch(base) flags += [ "--host", base == "expo" ? "localhost" : "127.0.0.1" ] command + flags end |