sdoc_live 0.1.11 → 0.1.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2632d4b9ea967fd91af45d93010c1f507813c88ed9665a1592ff9667fd65d300
4
- data.tar.gz: 5160265deb94355bf35d442f192cc2917f4900e887e69911039755af4135508a
3
+ metadata.gz: 5650fe4d2019c3e87194df2b3991e1353be042296fb48d4d6401832981aae200
4
+ data.tar.gz: 0a2aa835270a49e4e053e7c6e43de03cab05c335ce1bf3f28633d7db82bf7ce1
5
5
  SHA512:
6
- metadata.gz: ab62868d6ea0993036eb970cee004df241813b6b7183784893a329774238496045e9f5af87fe747015bb302d733e0c6b638a105c8d0e32562934037a914f4a95
7
- data.tar.gz: 3c864f88b8eebe761424c695ee85ba0bad5659e51ee3e5bc38d5fdbaa16a929f085cb2c5a7df572d161ba64ce71a635d1a186c732ddfc045183b369c5604fc83
6
+ metadata.gz: d3370cd47fb6b9c436cf25f4b2da691c6da616bc225039393887be61133b8e20a7ca00b3bc107eba25fff09d906e8e164c0f859668fc29457141fada77960cf5
7
+ data.tar.gz: 0aee08711b0940fe269167b1e583b4578884d25c72b596cd7810be10e1bdcf4daeede3bed516bf033fccb4e805c548d8227409a1a2daf20afbbe7ef2e88f9a34
@@ -11,7 +11,12 @@ module SdocLive
11
11
  doc_root = (config.output_dir || Rails.root.join("tmp", "doc")).to_s
12
12
  mount_path = config.mount_path
13
13
 
14
- Rails.application.middleware.insert_before(Rails::Rack::Logger, SdocLive::StaticFiles, doc_root, mount_path)
14
+ Rails.application.middleware.insert_before(
15
+ Rails::Rack::Logger,
16
+ SdocLive::StaticFiles,
17
+ doc_root,
18
+ mount_path
19
+ )
15
20
  end
16
21
 
17
22
  end
@@ -20,41 +25,31 @@ module SdocLive
20
25
 
21
26
  def initialize(app, doc_root, mount_path)
22
27
  @app = app
23
- @doc_root = doc_root
24
28
  @mount_path = mount_path.chomp("/")
29
+ @file_handler = ActionDispatch::FileHandler.new(
30
+ doc_root,
31
+ headers: { "cache-control" => "public, max-age=3600" }
32
+ )
25
33
  end
26
34
 
27
35
  def call(env)
28
36
  path_info = env["PATH_INFO"]
29
37
 
30
38
  if path_info == @mount_path
31
- query = env["QUERY_STRING"].to_s.empty? ? "" : "?#{ env['QUERY_STRING'] }"
32
- return [301, { "location" => "#{ @mount_path }/#{ query }" }, []]
39
+ query = env["QUERY_STRING"].to_s.empty? ? "" : "?#{env['QUERY_STRING']}"
40
+ return [301, { "location" => "#{@mount_path}/#{query}" }, []]
33
41
  end
34
42
 
35
- return @app.call(env) unless path_info.start_with?("#{ @mount_path }/")
36
-
37
- relative_path = path_info.delete_prefix(@mount_path)
38
- relative_path = "/index.html" if relative_path == "/"
39
-
40
- file_path = File.join(@doc_root, relative_path)
41
- file_path = File.join(file_path, "index.html") if File.directory?(file_path)
42
-
43
- if File.file?(file_path)
44
- serve_file(file_path)
45
- else
46
- @app.call(env)
43
+ if path_info.start_with?("#{@mount_path}/")
44
+ env["PATH_INFO"] = path_info.delete_prefix(@mount_path)
45
+ response = @file_handler.attempt(env)
46
+ env["PATH_INFO"] = path_info
47
+ return response if response
47
48
  end
48
- end
49
-
50
- private
51
49
 
52
- def serve_file(path)
53
- content_type = Rack::Mime.mime_type(File.extname(path), "application/octet-stream")
54
- body = File.read(path, mode: "rb")
55
- [200, { "content-type" => content_type, "content-length" => body.bytesize.to_s }, [body]]
50
+ @app.call(env)
56
51
  end
57
52
 
58
53
  end
59
54
 
60
- end
55
+ end
@@ -1,5 +1,5 @@
1
1
  module SdocLive
2
2
 
3
- VERSION = "0.1.11"
3
+ VERSION = "0.1.13"
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdoc_live
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - 16554289+optimuspwnius@users.noreply.github.com