rails-pwa 0.1.2 → 0.1.3

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: c4811d830ba5b148efc86a73fcf49d4d1a1b259f59ee50c0a6bfb1da8de7a164
4
- data.tar.gz: 8d98f29ad9414c35261fb1c115ed8dc213e6d76e9dd860f42c2edcff3e4639a0
3
+ metadata.gz: 3244af30921cbd3649866dc9920f6ac7cc6928e2752e56dc8198c22ecb747c94
4
+ data.tar.gz: 9f124aeb326d6b8d70f2a981ad7e95101645c5727d0582a34f372f2f5889fbd8
5
5
  SHA512:
6
- metadata.gz: a370a3dc95b8f933fae24df705c277227c282da8a7cc9754adf371c8be26729b158b81eb8ca56c64cbbdb34d974c56a4033b290d536e33ab605cd8ebd89c07f6
7
- data.tar.gz: aa18469b4035d78c290601948f2af7d3ba129d2baadae3bc04d2b890def06d19ae3df33b217197f4be579384c8c1ccac50d03817eee6bf4a730aa2508f6d33d5
6
+ metadata.gz: 98868d94a06273931e040cf078fc241e117b383c8f0fdfd799e445a98340fdd603fb4658ba3495715f91812e73f12f872b5e904cece36f97991fd072a2c95bd4
7
+ data.tar.gz: c8ff81cc8c89efe14adcb1fc90b95741fdbcd48ef2a0dc7b6e16d7f2a2b86fcf687cd3654686a3262452b4d4ca73c983a1802a93aa7c9c52586c7033a2b9247b
data/README.md CHANGED
@@ -1,8 +1,34 @@
1
- # Rails::Pwa
2
- Short description and motivation.
1
+ # Rails::PWA
2
+ A simple hack to serve service worker scripts from rails apps.
3
+
4
+ _TLDR_: Serves the webpack defined at `app/javascripts/packs/worker.js` from `/worker.js`
5
+
6
+ Service workers can only intercept requests in the directory and subdirectory they are served from. Rails serves webpacked javascript from paths similar to `/packs/js/application-abcd1234.js`. Any service worker served from a path like this would only be able to operate on paths under `/packs/js/`; generally not what you want.
7
+
8
+ This gem lets you create a javascript pack for a service worker, and serve it from `/worker.js`.
3
9
 
4
10
  ## Usage
5
- How to use my plugin.
11
+ Install the gem (see full instructions below).
12
+
13
+ Restart your server (so the gem's middleware can be added to the app).
14
+
15
+ Add a service worker pack by creating a file `app/javascript/packs/worker.js`. Here's a simple example to get started:
16
+
17
+ ```js
18
+ for (const name of ["install", "activate", "fetch"]) {
19
+ self.addEventListener(name, event => console.log(event))
20
+ }
21
+ ```
22
+
23
+ You also need to register your worker, adding something like this to `app/javascript/packs/application.js`:
24
+
25
+ ```
26
+ if ("serviceWorker" in navigator) {
27
+ window.addEventListener("load", function () {
28
+ navigator.serviceWorker.register("/worker.js")
29
+ })
30
+ }
31
+ ```
6
32
 
7
33
  ## Installation
8
34
  Add this line to your application's Gemfile:
@@ -21,8 +47,12 @@ Or install it yourself as:
21
47
  $ gem install rails-pwa
22
48
  ```
23
49
 
24
- ## Contributing
25
- Contribution directions go here.
50
+ ## How it works
51
+
52
+ This gem installs a very simple piece of `Rack::Middleware` into your app, which intercepts all requests to `/worker.js` and either:
53
+
54
+ * In development: Rewrites and forwards the request to the rails app (where the usual webpacker magic will occure)
55
+ * In other environments: Serves the precompiled `worker.js` pack directly from `/public/packs/js/`. N.B. You may want to use some other form of url rewriting in production, depending on how your app is deployed.
26
56
 
27
57
  ## License
28
58
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -10,7 +10,7 @@ class Rails::PWA::Railtie < ::Rails::Railtie
10
10
  scripts = app.config.pwa.scripts
11
11
  root = Rails.env.development? ? false : Rails.public_path
12
12
 
13
- app.config.app_middleware.use Rails::PWA::Interceptor,
13
+ app.config.middleware.insert_before Rack::Sendfile, Rails::PWA::Interceptor,
14
14
  scripts: app.config.pwa.scripts,
15
15
  root: root
16
16
  end
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module PWA
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-pwa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Ward
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 6.0.0.rc1
19
+ version: 6.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 6.0.0.rc1
26
+ version: 6.0.0
27
27
  description: Serves service worker scripts
28
28
  email:
29
29
  - tom@popdog.net