static-rails 0.0.4 → 0.0.5

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: 14d31f3821438735e307f98dd5f4a48215d0b1d678915369a7abd459b3b40145
4
- data.tar.gz: bc7b15c689693e533a75ac378db060396cde1839edb0acffc04c30e18872bf77
3
+ metadata.gz: 3159e387c25a9742f063230f554490e70d41e4be4a318eed738e26480c048cb6
4
+ data.tar.gz: da86a266cb8bd5559e5ec71d90a84c0ca0539449d8f7259d1ed0654abe3a0c64
5
5
  SHA512:
6
- metadata.gz: f645e5e515d712acd3c1a81935d560d3ef0f2be3a42e5fd42af4320cf6a4ae25e14843b0c076dfda4ec5b980a12cc436cfbef527768704f97c6e89ac2e7e17f6
7
- data.tar.gz: 61600757a2e549dc5bff49b8fe01da9c0f45eac4a1fd6ba815ea4aafb5655270bfa457ac76c98a0927b98e61bcf741b40a0089f0cfb55f612ad0de386b0fa9d4
6
+ metadata.gz: 4be0b00df5deaacc0c414bf743b78b5feff4f589e44b93378d5de40458e9f56733c83315f9e58cfa9d08c0627d26193994bbec01f86b18924e980e7dc8271f3b
7
+ data.tar.gz: 1c42430d7193cf13eb21579f5647ecd53f07e010092c2056bef17848aed64a588c8c5919241760fb867e67734d2878559f127c6347b082fe5ef4c77387cc6454
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.0.5
2
+
3
+ * Add a site option `compile_404_file_path` to specify a file to be used as a
4
+ 404 page when serving compiled assets and no file is found
5
+
1
6
  ## 0.0.4
2
7
 
3
8
  * Add a cookie named `_csrf_token` by default to all static site requests, so
data/Gemfile.lock CHANGED
@@ -1,27 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- static-rails (0.0.4)
4
+ static-rails (0.0.5)
5
5
  rack-proxy (~> 0.6)
6
6
  railties (>= 5.0.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionpack (6.0.3)
12
- actionview (= 6.0.3)
13
- activesupport (= 6.0.3)
11
+ actionpack (6.0.3.1)
12
+ actionview (= 6.0.3.1)
13
+ activesupport (= 6.0.3.1)
14
14
  rack (~> 2.0, >= 2.0.8)
15
15
  rack-test (>= 0.6.3)
16
16
  rails-dom-testing (~> 2.0)
17
17
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
18
- actionview (6.0.3)
19
- activesupport (= 6.0.3)
18
+ actionview (6.0.3.1)
19
+ activesupport (= 6.0.3.1)
20
20
  builder (~> 3.1)
21
21
  erubi (~> 1.4)
22
22
  rails-dom-testing (~> 2.0)
23
23
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
24
- activesupport (6.0.3)
24
+ activesupport (6.0.3.1)
25
25
  concurrent-ruby (~> 1.0, >= 1.0.2)
26
26
  i18n (>= 0.7, < 2)
27
27
  minitest (~> 5.1)
@@ -56,9 +56,9 @@ GEM
56
56
  nokogiri (>= 1.6)
57
57
  rails-html-sanitizer (1.3.0)
58
58
  loofah (~> 2.3)
59
- railties (6.0.3)
60
- actionpack (= 6.0.3)
61
- activesupport (= 6.0.3)
59
+ railties (6.0.3.1)
60
+ actionpack (= 6.0.3.1)
61
+ activesupport (= 6.0.3.1)
62
62
  method_source
63
63
  rake (>= 0.8.7)
64
64
  thor (>= 0.20.3, < 2.0)
data/README.md CHANGED
@@ -153,6 +153,10 @@ To tell the gem about your static sites, assign an array of hashes as `sites`
153
153
  path to which production assets are compiled, relative to the site's
154
154
  `source_dir`
155
155
 
156
+ * **compile_404_file_path** (Optional) When `serve_compiled_assets` is true,
157
+ this file (relative to the `compile_dir`) will be served whenever the
158
+ request's path does not match a file on disk
159
+
156
160
  ## Configuring your static site generators
157
161
 
158
162
  Assuming you won't be mounting your static site to your app's root `/` path,
@@ -66,6 +66,9 @@ StaticRails.config do |config|
66
66
  #
67
67
  # # The destination of production-compiled assets, relative to Rails root
68
68
  # compile_dir: "static/blog/dist"
69
+ #
70
+ # # A 404 page to be sent when serving compiled assets and no file matches
71
+ # compile_404_file_path: "404.html"
69
72
  # },
70
73
  ]
71
74
  end
@@ -13,10 +13,10 @@ module StaticRails
13
13
  # When Rails invokes our Railtie, we'll save off a reference to the Rails app
14
14
  attr_accessor :app
15
15
 
16
- # When true, the ProxyMiddleware will be added
16
+ # When true, our middleware will proxy requests to static site servers
17
17
  attr_accessor :proxy_requests
18
18
 
19
- # When true, the StaticMiddleware will be added
19
+ # When true, our middleware will serve sites' compiled asset files
20
20
  attr_accessor :serve_compiled_assets
21
21
 
22
22
  # Number of seconds to wait on sites to confirm servers are ready
@@ -14,6 +14,7 @@ module StaticRails
14
14
  :server_path,
15
15
  :compile_command,
16
16
  :compile_dir,
17
+ :compile_404_file_path,
17
18
  keyword_init: true
18
19
  )
19
20
 
@@ -17,7 +17,7 @@ module StaticRails
17
17
  if (req.get? || req.head?) && (site = @matches_request_to_static_site.call(req))
18
18
  file_handler = file_handler_for(site)
19
19
  path = req.path_info.gsub(/^#{site.url_root_path}/, "").chomp("/")
20
- if (match = file_handler.match?(path))
20
+ if (match = matching_file_for(file_handler, site, path))
21
21
  req.path_info = match
22
22
  return file_handler.serve(req)
23
23
  end
@@ -35,5 +35,13 @@ module StaticRails
35
35
  StaticRails.config.app.root.join(site.compile_dir).to_s
36
36
  )
37
37
  end
38
+
39
+ def matching_file_for(file_handler, site, path)
40
+ if (match = file_handler.match?(path))
41
+ match
42
+ elsif site.compile_404_file_path.present?
43
+ file_handler.match?(site.compile_404_file_path)
44
+ end
45
+ end
38
46
  end
39
47
  end
@@ -1,3 +1,3 @@
1
1
  module StaticRails
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -62,7 +62,6 @@ files:
62
62
  - lib/static-rails.rb
63
63
  - lib/static-rails/compile.rb
64
64
  - lib/static-rails/configuration.rb
65
- - lib/static-rails/csrf_middleware.rb
66
65
  - lib/static-rails/determines_whether_to_handle_request.rb
67
66
  - lib/static-rails/error.rb
68
67
  - lib/static-rails/gets_csrf_token.rb
@@ -1,20 +0,0 @@
1
- require_relative "gets_csrf_token"
2
-
3
- module StaticRails
4
- class CsrfMiddleware
5
- def initialize(app)
6
- @app = app
7
- @gets_csrf_token = GetsCsrfToken.new
8
- end
9
-
10
- def call(env)
11
- if env["__static_rails_evil_request_for_csrf_token"]
12
- req = Rack::Request.new(env)
13
- [200, {}, [@gets_csrf_token.call(req)]].tap do
14
- end
15
- else
16
- @app.call(env)
17
- end
18
- end
19
- end
20
- end