simple-httpd 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce94e11efef98e3e29ead50e0259c53897af676dc24a647412470c0081eca2a8
4
- data.tar.gz: 4a855b09b2d93cfd20a3e3034d45a997008faade88a9fd479443a1e2fbb420aa
3
+ metadata.gz: 265655ee2ae92a528dc710e3daec1bc0e3249af73450d41817a2295934bf3315
4
+ data.tar.gz: 4eb732b11012cbd503076ecf0b64c05765020539fce6d86c0902074a1dfb0150
5
5
  SHA512:
6
- metadata.gz: 46a3f829100f9bcc91e2101271dfc12e187d331c9c5b65a8993609b7bb7025f76605354880b4a0a998190573552b5f1a209bb148c648dd1375028fd60f19201c
7
- data.tar.gz: 810c4561326ff0ab3a2cf45ab64fd5e2c6a106dcfc81a5012b14a2d305f6ce0253c4aa5e4e070f178fb29a3ac88d1c1c0b7821f6d7ab38dda095e5079721c969
6
+ metadata.gz: 0c4c22dde10ce2ad09fabcee176b37004b39176dddb68b3c511a82d6280ac3b4a338c2aa43aabf4827bc4b91e56cb35c0d58d488753a38523cf795a82fde2918
7
+ data.tar.gz: 65fa2846cee1a99db0cdd736848baff796b6412036c74d6870cbd09c475a05c4464baffbf38c75c872c498defa32d4fa9e7712d5285609993b9093c2d47bf800
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
data/lib/simple-httpd.rb CHANGED
@@ -1,3 +1 @@
1
- # rubocop:disable Naming/FileName
2
-
3
1
  require "simple/httpd"
@@ -1,3 +1 @@
1
- # rubocop:disable Naming/FileName
2
-
3
1
  require "simple/service"
data/lib/simple/httpd.rb CHANGED
@@ -31,6 +31,8 @@ class Simple::Httpd
31
31
  end
32
32
 
33
33
  require "simple/service"
34
+
35
+ require "simple/httpd/debugging"
34
36
  require "simple/httpd/helpers"
35
37
  require "simple/httpd/reloader"
36
38
  require "simple/httpd/base_controller"
@@ -151,7 +151,7 @@ class Simple::Httpd::BaseController
151
151
 
152
152
  # -- print unspecified errors.
153
153
 
154
- if ::Simple::Httpd.env == "development"
154
+ if ::Simple::Httpd.env != "development"
155
155
  error do |exc|
156
156
  content_type :text
157
157
  status 500
@@ -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
@@ -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
- path = path.gsub(/\/$/, "") # remove trailing "/"
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
- new(mount_point, path)
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 + ["#{path}/routes.rb"],
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
- request_path = env["PATH_INFO"]
42
- if serve_file?(request_path)
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 serve_file?(request_path)
54
- @static_files.include?(request_path[1..-1])
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.1
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: 2019-12-25 00:00:00.000000000 Z
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