simple-httpd 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/simple-httpd.rb +0 -2
- data/lib/simple-service.rb +0 -2
- data/lib/simple/httpd.rb +2 -0
- data/lib/simple/httpd/base_controller/error_handling.rb +1 -1
- data/lib/simple/httpd/debugging.rb +17 -0
- data/lib/simple/httpd/mount.rb +5 -2
- data/lib/simple/httpd/rack/dynamic_mount.rb +9 -3
- data/lib/simple/httpd/rack/static_mount.rb +23 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 265655ee2ae92a528dc710e3daec1bc0e3249af73450d41817a2295934bf3315
|
4
|
+
data.tar.gz: 4eb732b11012cbd503076ecf0b64c05765020539fce6d86c0902074a1dfb0150
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c4c22dde10ce2ad09fabcee176b37004b39176dddb68b3c511a82d6280ac3b4a338c2aa43aabf4827bc4b91e56cb35c0d58d488753a38523cf795a82fde2918
|
7
|
+
data.tar.gz: 65fa2846cee1a99db0cdd736848baff796b6412036c74d6870cbd09c475a05c4464baffbf38c75c872c498defa32d4fa9e7712d5285609993b9093c2d47bf800
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/lib/simple-httpd.rb
CHANGED
data/lib/simple-service.rb
CHANGED
data/lib/simple/httpd.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require "pry"
|
3
|
+
rescue LoadError
|
4
|
+
class Binding
|
5
|
+
def pry
|
6
|
+
STDERR.puts "*** 'binding.pry' not supported: add the 'pry-byebug' gem to your Gemfile."
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
require "byebug"
|
13
|
+
rescue LoadError
|
14
|
+
def byebug
|
15
|
+
STDERR.puts "*** 'byebug' not supported: add the 'byebug' gem to your Gemfile."
|
16
|
+
end
|
17
|
+
end
|
data/lib/simple/httpd/mount.rb
CHANGED
@@ -38,7 +38,8 @@ module Simple::Httpd::Mount
|
|
38
38
|
attr_reader :path, :mount_point
|
39
39
|
|
40
40
|
def self.build(mount_point, path:)
|
41
|
-
|
41
|
+
mount_point = mount_point.gsub(/\/.$/, "/") # shorting trailing "/." to "/"
|
42
|
+
path = path.gsub(/\/$/, "") # remove trailing "/"
|
42
43
|
|
43
44
|
raise ArgumentError, "You probably don't want to mount your root directory, check mount" if path == ""
|
44
45
|
return unless Dir.exist?(path)
|
@@ -57,10 +58,12 @@ module Simple::Httpd::Mount
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def build_rack_apps
|
61
|
+
return @build_rack_apps if @build_rack_apps
|
62
|
+
|
60
63
|
dynamic_mount = Rack::DynamicMount.build(mount_point, path)
|
61
64
|
static_mount = Rack::StaticMount.build(mount_point, path)
|
62
65
|
|
63
|
-
[dynamic_mount, static_mount].compact
|
66
|
+
@build_rack_apps = [dynamic_mount, static_mount].compact
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
@@ -8,9 +8,15 @@ class Simple::Httpd::Rack::DynamicMount
|
|
8
8
|
|
9
9
|
extend Forwardable
|
10
10
|
|
11
|
+
# Tries to build a DynamicMount mount point at a gievn path. This is only
|
12
|
+
# successful if the path location has a "routes.rb" file.
|
11
13
|
def self.build(mount_point, path)
|
12
14
|
expect! path => String
|
13
|
-
|
15
|
+
|
16
|
+
routes = File.join(path, "routes.rb")
|
17
|
+
return unless File.exist?(routes)
|
18
|
+
|
19
|
+
new(mount_point, path, routes)
|
14
20
|
end
|
15
21
|
|
16
22
|
def call(env)
|
@@ -22,14 +28,14 @@ class Simple::Httpd::Rack::DynamicMount
|
|
22
28
|
attr_reader :path
|
23
29
|
attr_reader :mount_point
|
24
30
|
|
25
|
-
def initialize(mount_point, path)
|
31
|
+
def initialize(mount_point, path, routes)
|
26
32
|
@mount_point = mount_point
|
27
33
|
@path = path.gsub(/\/\z/, "") # remove trailing "/"
|
28
34
|
|
29
35
|
::Simple::Httpd::Reloader.attach self, paths: service_files, reloading_instance: nil
|
30
36
|
|
31
37
|
@rack_app = H.subclass ::Simple::Httpd::BaseController,
|
32
|
-
paths: helper_files + [
|
38
|
+
paths: helper_files + [routes],
|
33
39
|
description: "<controller:#{H.shorten_path(path)}>"
|
34
40
|
|
35
41
|
@rack_app.route_descriptions.each do |route|
|
@@ -3,7 +3,7 @@ class Simple::Httpd::Rack::StaticMount
|
|
3
3
|
H = ::Simple::Httpd::Helpers
|
4
4
|
Rack = ::Simple::Httpd::Rack
|
5
5
|
|
6
|
-
EXTENSIONS = %w(.txt .md .js .css .png .jpeg .jpg)
|
6
|
+
EXTENSIONS = %w(.txt .md .js .css .png .jpeg .jpg .html)
|
7
7
|
GLOB_PATTERN = "**/*.{#{EXTENSIONS.map { |s| s[1..-1] }.join(",")}}"
|
8
8
|
|
9
9
|
def self.build(mount_point, path)
|
@@ -15,6 +15,12 @@ class Simple::Httpd::Rack::StaticMount
|
|
15
15
|
"#{mount_point}: serving #{static_files.count} static file(s)"
|
16
16
|
end
|
17
17
|
|
18
|
+
if ::Simple::Httpd.logger.debug?
|
19
|
+
static_files.sort.each do |file|
|
20
|
+
::Simple::Httpd.logger.debug "#{mount_point}/#{file}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
18
24
|
new(mount_point, path, static_files)
|
19
25
|
end
|
20
26
|
|
@@ -38,9 +44,8 @@ class Simple::Httpd::Rack::StaticMount
|
|
38
44
|
public
|
39
45
|
|
40
46
|
def call(env)
|
41
|
-
|
42
|
-
if
|
43
|
-
file_path = request_path[1..-1]
|
47
|
+
file_path = lookup_static_file(env["PATH_INFO"])
|
48
|
+
if file_path
|
44
49
|
env["PATH_INFO"] = file_path
|
45
50
|
@file_server.call(env)
|
46
51
|
else
|
@@ -50,7 +55,19 @@ class Simple::Httpd::Rack::StaticMount
|
|
50
55
|
|
51
56
|
private
|
52
57
|
|
53
|
-
def
|
54
|
-
|
58
|
+
def lookup_static_file(path_info)
|
59
|
+
relative_path = path_info[1..-1]
|
60
|
+
return relative_path if @static_files.include?(relative_path)
|
61
|
+
|
62
|
+
# determine potential index paths
|
63
|
+
index_paths = %w(index.html README.md)
|
64
|
+
|
65
|
+
if relative_path != ""
|
66
|
+
index_paths = index_paths.map do |index_file|
|
67
|
+
File.join(relative_path, index_file)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
(index_paths & @static_files.to_a).first
|
55
72
|
end
|
56
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-httpd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: neatjson
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- lib/simple/httpd/base_controller/result.rb
|
131
131
|
- lib/simple/httpd/base_controller/x_processing.rb
|
132
132
|
- lib/simple/httpd/cli.rb
|
133
|
+
- lib/simple/httpd/debugging.rb
|
133
134
|
- lib/simple/httpd/helpers.rb
|
134
135
|
- lib/simple/httpd/mount.rb
|
135
136
|
- lib/simple/httpd/rack.rb
|