Skip to content

Commit

Permalink
(3.5.0) Add setting for disabling automatically inserting middleware.…
Browse files Browse the repository at this point in the history
… Change installation flow. (#170)
  • Loading branch information
bstewart00 authored Apr 14, 2021
1 parent fabbe2f commit b08da57
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
24 changes: 24 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ config.wovnrb = {
...
```

The WOVN.rb Rails middleware must also be installed. See [2.10 - install_middleware](#2.10-install_middleware)

* If you're using Sinatra

Insert the following into either the Application File or config.ru.
Expand Down Expand Up @@ -83,6 +85,7 @@ query | | []
ignore_class | | []
translate_fragment | | true
ignore_paths | | []
install_middleware | | true

### 2.1. project_token

Expand Down Expand Up @@ -172,3 +175,24 @@ For instance, if you want to not localize the admin directory of your website, y
```
'ignore_paths' => ['/admin/']
```

### 2.10 install_middleware

When using WOVN.rb in a Rails environment, this parameter controls whether the WOVN.rb middleware will be automatically installed or not.

By default, WOVN.rb is automatically installed as the first middleware.
If you are using Rack::Deflater or other middleware that needs to be executed first, set this parameter to `false` and manually insert the middleware appropriately.
WOVN.rb needs to be added after any compression middleware.

```ruby
config.middleware.use Rack::Deflater
config.middleware.insert_after Rack::Deflater, Wovnrb::Interceptor

config.wovnrb = {
:project_token => 'EnS!t3',
:default_lang => 'en',
:supported_langs => ['en'],
:url_pattern => 'path',
:install_middleware => false
}
```
16 changes: 1 addition & 15 deletions lib/wovnrb/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
module Wovnrb
def self.middleware_inserted?(app, middleware)
app.middleware.send(:operations).each do |_, middlewares, _|
return true if middlewares&.include?(middleware)
end

false
end

class Railtie < Rails::Railtie
initializer 'wovnrb.configure_rails_initialization' do |app|
unless Wovnrb.middleware_inserted?(app, Wovnrb::Interceptor)
if defined?(Rack::Deflater) && Wovnrb.middleware_inserted?(app, Rack::Deflater)
app.middleware.insert_after(Rack::Deflater, Wovnrb::Interceptor)
else
app.middleware.insert_before(0, Wovnrb::Interceptor)
end
end
app.middleware.insert_before(0, Wovnrb::Interceptor) if Rails.configuration.wovnrb[:install_middleware]
end
end
end
2 changes: 1 addition & 1 deletion lib/wovnrb/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Wovnrb
VERSION = '2.6.0'.freeze
VERSION = '3.0.0'.freeze
end

0 comments on commit b08da57

Please sign in to comment.