webpacker-pwa 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 15d6f7e278d5f03064a42d65196183da6b78987d096c36b76948aadf61754e92
4
+ data.tar.gz: 10293b967d75603a0d69344684edd465cf567d9cb785b5d874bc67e39e4ec572
5
+ SHA512:
6
+ metadata.gz: 6712abab6f9b293996a38fed02004b24e28cd750b70ec1a553b8a66ce9c1cac0b73b9f1b44b998cffc47ee682efd2da62fd2e55915d85bb8b0bb4af3926f016e
7
+ data.tar.gz: a967a9400f8d469eae6c0c86bc8db2159b17794fdba9b5a94b79aa30ef77332ee0355fd0379c7a10478a62af80401790cd5e41321a69e3367fdf0cabdf9d7175
@@ -0,0 +1,5 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------------------------- | ------ | --------------- |
3
+ ./spec/webpacker/pwa/dev_server_proxy_spec.rb[1:1:1] | passed | 0.0414 seconds |
4
+ ./spec/webpacker/pwa/dev_server_proxy_spec.rb[1:2:1] | passed | 0.00139 seconds |
5
+ ./spec/webpacker/pwa/version_spec.rb[1:1] | passed | 0.00269 seconds |
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in webpacker-pwa.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,96 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ webpacker-pwa (0.1.0)
5
+ rack-proxy (>= 0.6.1)
6
+ webpacker (>= 4.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionpack (6.0.3.1)
12
+ actionview (= 6.0.3.1)
13
+ activesupport (= 6.0.3.1)
14
+ rack (~> 2.0, >= 2.0.8)
15
+ rack-test (>= 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
18
+ actionview (6.0.3.1)
19
+ activesupport (= 6.0.3.1)
20
+ builder (~> 3.1)
21
+ erubi (~> 1.4)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
24
+ activesupport (6.0.3.1)
25
+ concurrent-ruby (~> 1.0, >= 1.0.2)
26
+ i18n (>= 0.7, < 2)
27
+ minitest (~> 5.1)
28
+ tzinfo (~> 1.1)
29
+ zeitwerk (~> 2.2, >= 2.2.2)
30
+ builder (3.2.4)
31
+ concurrent-ruby (1.1.6)
32
+ crass (1.0.6)
33
+ diff-lcs (1.3)
34
+ erubi (1.9.0)
35
+ i18n (1.8.2)
36
+ concurrent-ruby (~> 1.0)
37
+ loofah (2.5.0)
38
+ crass (~> 1.0.2)
39
+ nokogiri (>= 1.5.9)
40
+ method_source (1.0.0)
41
+ mini_portile2 (2.4.0)
42
+ minitest (5.14.1)
43
+ nokogiri (1.10.9)
44
+ mini_portile2 (~> 2.4.0)
45
+ rack (2.2.2)
46
+ rack-proxy (0.6.5)
47
+ rack
48
+ rack-test (1.1.0)
49
+ rack (>= 1.0, < 3)
50
+ rails-dom-testing (2.0.3)
51
+ activesupport (>= 4.2.0)
52
+ nokogiri (>= 1.6)
53
+ rails-html-sanitizer (1.3.0)
54
+ loofah (~> 2.3)
55
+ railties (6.0.3.1)
56
+ actionpack (= 6.0.3.1)
57
+ activesupport (= 6.0.3.1)
58
+ method_source
59
+ rake (>= 0.8.7)
60
+ thor (>= 0.20.3, < 2.0)
61
+ rake (12.3.3)
62
+ rspec (3.9.0)
63
+ rspec-core (~> 3.9.0)
64
+ rspec-expectations (~> 3.9.0)
65
+ rspec-mocks (~> 3.9.0)
66
+ rspec-core (3.9.2)
67
+ rspec-support (~> 3.9.3)
68
+ rspec-expectations (3.9.2)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.9.0)
71
+ rspec-mocks (3.9.1)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.9.0)
74
+ rspec-support (3.9.3)
75
+ semantic_range (2.3.0)
76
+ thor (1.0.1)
77
+ thread_safe (0.3.6)
78
+ tzinfo (1.2.7)
79
+ thread_safe (~> 0.1)
80
+ webpacker (5.1.1)
81
+ activesupport (>= 5.2)
82
+ rack-proxy (>= 0.6.1)
83
+ railties (>= 5.2)
84
+ semantic_range (>= 2.3.0)
85
+ zeitwerk (2.3.0)
86
+
87
+ PLATFORMS
88
+ ruby
89
+
90
+ DEPENDENCIES
91
+ rake (~> 12.0)
92
+ rspec (~> 3.0)
93
+ webpacker-pwa!
94
+
95
+ BUNDLED WITH
96
+ 2.1.4
@@ -0,0 +1,29 @@
1
+ # webpacker-pwa
2
+
3
+ A Rack Middleware to serve service workers when runnning webpack-dev-server.
4
+ Webpacker middleware, by default, redirects only requests to `/packs` to webpack-dev-server,
5
+ and since our service workers live in the `public` folder, they cannot be served.
6
+
7
+ This gem fixes this issue by adding a Rack Middleware responsible of serving service workers files.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'webpacker-pwa', group: :development
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install webpacker-pwa
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "webpacker/pwa"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ require "webpacker/pwa/dev_server_proxy"
2
+ require "webpacker/pwa/version"
3
+
4
+ require "webpacker/pwa/railtie" if defined?(Rails)
@@ -0,0 +1,45 @@
1
+ require "rack/proxy"
2
+ require "webpacker"
3
+
4
+ module Webpacker
5
+ module Pwa
6
+ class DevServerProxy < Rack::Proxy
7
+ def initialize(app = nil, opts = {})
8
+ @webpacker = opts.delete(:webpacker) || Webpacker.instance
9
+ opts[:streaming] = false if Rails.env.test? && !opts.key?(:streaming)
10
+ super
11
+ end
12
+
13
+ def perform_request(env)
14
+ service_workers_entry_path = dev_server.config.send(:fetch, :service_workers_entry_path)
15
+ return unless service_workers_entry_path.present?
16
+ service_workers_folder = dev_server.config.source_path.join(service_workers_entry_path)
17
+ service_workers = Dir[service_workers_folder.join('*')].map { |e| "/#{File.basename(e)}" }
18
+ if (service_workers.include?(env["PATH_INFO"])) && dev_server.running?
19
+ env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = dev_server.host
20
+ env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port
21
+ env["HTTP_PORT"] = env["HTTP_X_FORWARDED_PORT"] = dev_server.port.to_s
22
+ env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = dev_server.protocol
23
+ unless dev_server.https?
24
+ env["HTTPS"] = env["HTTP_X_FORWARDED_SSL"] = "off"
25
+ end
26
+ env["SCRIPT_NAME"] = ""
27
+
28
+ super(env)
29
+ else
30
+ @app.call(env)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def config
37
+ @webpacker.config
38
+ end
39
+
40
+ def dev_server
41
+ @webpacker.dev_server
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ require "rails/railtie"
2
+
3
+ module Webpacker
4
+ module Pwa
5
+ class Railtie < Rails::Railtie
6
+ initializer "webpacker-pwa.proxy" do |app|
7
+ insert_middleware = Webpacker.config.dev_server.present? rescue nil
8
+ if insert_middleware
9
+ app.middleware.insert_before 0,
10
+ Rails::VERSION::MAJOR >= 5 ?
11
+ Webpacker::Pwa::DevServerProxy : "Webpacker::Pwa::DevServerProxy",
12
+ ssl_verify_none: true
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Webpacker
2
+ module Pwa
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/webpacker/pwa/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "webpacker-pwa"
5
+ spec.version = Webpacker::Pwa::VERSION
6
+ spec.authors = ["Alessandro Rodi"]
7
+ spec.email = ["alessandro.rodi@renuo.ch"]
8
+
9
+ spec.summary = %q{webpacker-pwa enables you to serve service workers with webpack-dev-server}
10
+ spec.homepage = "https://github.com/coorasse/webpacker-pwa"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/coorasse/webpacker-pwa"
16
+ spec.metadata["changelog_uri"] = "https://github.com/coorasse/webpacker-pwa/CHANGELOG.md"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency "rack-proxy", ">= 0.6.1"
28
+ spec.add_dependency "webpacker", ">= 4.0.0"
29
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webpacker-pwa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alessandro Rodi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack-proxy
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: webpacker
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
41
+ description:
42
+ email:
43
+ - alessandro.rodi@renuo.ch
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec_status"
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/webpacker/pwa.rb
56
+ - lib/webpacker/pwa/dev_server_proxy.rb
57
+ - lib/webpacker/pwa/railtie.rb
58
+ - lib/webpacker/pwa/version.rb
59
+ - webpacker-pwa.gemspec
60
+ homepage: https://github.com/coorasse/webpacker-pwa
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ homepage_uri: https://github.com/coorasse/webpacker-pwa
65
+ source_code_uri: https://github.com/coorasse/webpacker-pwa
66
+ changelog_uri: https://github.com/coorasse/webpacker-pwa/CHANGELOG.md
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.3.0
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.0.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: webpacker-pwa enables you to serve service workers with webpack-dev-server
86
+ test_files: []