]>
Lady’s Gitweb - HOMEDIR/blob - rb/public-serve.rb
2 # @(#)🏠📂 HOMEDIR rb/public-serve.rb 2026-03-22T02:03:39Z
3 # SPDX-FileCopyrightText: 2025, 2026 Lady <https://www.ladys.computer/about/#lady>
4 # SPDX-License-Identifier: CC0-1.0
6 ## ⁌ Public File Server
8 ## This script offers a profoundly simple file server which uses
9 ## `index.xhtml´ as its index file.
10 ## It is written in what is hopefully a portable Ruby that will work
11 ## across most installations.
12 ## Ruby was chosen because Webrick is generally available.
16 ## The first argument is the desired localhost port, defaulting to
18 ## The second argument is the directory to serve.
19 ## This can also be provided with the `path_PUBDIR´ environment
21 ## The default directory is `@public.tmp´.
23 PORT
= ARGV[0] || 3000
25 server
= WEBrick
::HTTPServer.new(Port
: PORT
,
26 DocumentRoot
: ARGV[1] || ENV["path_PUBDIR"] || "@public.tmp",
27 DirectoryIndex
: ["index.xhtml"])
28 trap
'INT' do server
.shutdown
end
30 ## A minimal X·H·T·M·L file handler is provided which simply serves
31 ## files with the appropriate content type.
33 class XHTMLHandler
< WEBrick
::HTTPServlet::DefaultFileHandler
34 def do_GET request
, response
36 response
['Content-Type'] = 'application/xhtml+xml
'
39 WEBrick::HTTPServlet::FileHandler.add_handler("xhtml", XHTMLHandler)
41 ## A notice is printed before starting the server to clarify usage.
43 $stderr.puts <<INFOTEXT
45 \e[7m NOTE: \e[27m Visit <http://localhost:#{PORT}/> to view the site.
47 \e[7m \e[27m Press control + C to exit.
This page took 0.077316 seconds and 5 git commands to generate.