Class: Roxane::StaticServer
- Inherits:
-
Object
- Object
- Roxane::StaticServer
- Defined in:
- lib/roxane/static_server.rb
Overview
Tiny loopback-only static file server — dependency-free (stdlib sockets). It serves a built frontend bundle to the embedded webview over a real http:// origin, so ES modules / fetch / SPA routing behave (which file:// breaks), and the desktop path mirrors the hosted-web one (same frontend, local origin). GET-only, bound to 127.0.0.1, path-traversal-safe.
Constant Summary collapse
- MIME =
{ ".html" => "text/html", ".htm" => "text/html", ".js" => "text/javascript", ".mjs" => "text/javascript", ".css" => "text/css", ".json" => "application/json", ".map" => "application/json", ".svg" => "image/svg+xml", ".png" => "image/png", ".jpg" => "image/jpeg", ".jpeg" => "image/jpeg", ".gif" => "image/gif", ".webp" => "image/webp", ".ico" => "image/x-icon", ".woff" => "font/woff", ".woff2" => "font/woff2", ".ttf" => "font/ttf", ".wasm" => "application/wasm", ".txt" => "text/plain" }.freeze
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(root, spa: true) ⇒ StaticServer
constructor
A new instance of StaticServer.
-
#start ⇒ Object
Start on an ephemeral loopback port in a background thread; returns base URL.
- #stop ⇒ Object
Constructor Details
#initialize(root, spa: true) ⇒ StaticServer
Returns a new instance of StaticServer.
25 26 27 28 |
# File 'lib/roxane/static_server.rb', line 25 def initialize(root, spa: true) @root = File.(root) @spa = spa end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
23 24 25 |
# File 'lib/roxane/static_server.rb', line 23 def port @port end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
23 24 25 |
# File 'lib/roxane/static_server.rb', line 23 def root @root end |
Instance Method Details
#start ⇒ Object
Start on an ephemeral loopback port in a background thread; returns base URL.
31 32 33 34 35 36 |
# File 'lib/roxane/static_server.rb', line 31 def start @server = TCPServer.new("127.0.0.1", 0) @port = @server.addr[1] @thread = Thread.new { accept_loop } "http://127.0.0.1:#{@port}/" end |
#stop ⇒ Object
38 39 40 41 |
# File 'lib/roxane/static_server.rb', line 38 def stop @server&.close @thread&.kill end |