jj-middleware 3.0.3 → 3.1.0

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
  SHA1:
3
- metadata.gz: 78fb3bf581d7d3c5a80cb27f90298e1045551925
4
- data.tar.gz: 35b4d26a5a034414836148250fc6efadada28803
3
+ metadata.gz: 3f317b5db82cca5c4c981ce143646ae2eef4fb19
4
+ data.tar.gz: 362f85b29caee84acc3384d70966b12684a3560d
5
5
  SHA512:
6
- metadata.gz: e16a541e681d705481305be01e312d5b861821b64904f00770794f947b4d6a51a3e47dbabb3f76b4e91cff30e168c92621b9677a92924f334b54675274d015fd
7
- data.tar.gz: 44c75345dbd610cb68b085d9da2d295f216da12f5e96d5197920f17118ae0b257977c30d878b92c2d76a13fad58bb0905b6a5e36d95ce8477cba2db5c0d0414c
6
+ metadata.gz: b1967d1c2f795f0e899cec64e829a908c0c80c391e5f95c91fee2e8fbf78e2a891b01144b5700cb2aacded60c4686bdd0cc1525c69131caab8d9d792fcf56faf
7
+ data.tar.gz: 1325358a38bf6cb0392e26de2d1fdbe3001b25373c25e13565b66cd2fabe291edd60e09d24db4c3e865e51b5205c84520b00fd91d123f8ebe25fc896a9751d86
@@ -1,5 +1,5 @@
1
1
  module JJ
2
2
  module Middleware
3
- VERSION = '3.0.3'.freeze
3
+ VERSION = '3.1.0'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,39 @@
1
+ require 'rack/request'
2
+ require 'jj/middleware/base'
3
+
4
+ module JJ
5
+ module Middleware
6
+ class UsernameCorrection < Base
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ request = Rack::Request.new(env)
13
+ host_parts = request.host.split('.')
14
+ sub_domain = host_parts.shift
15
+
16
+ if sub_domain != CREATOR_SUB_DOMAIN && request.path != '/'
17
+ redirect(generate_path(host_parts, request), 301)
18
+ else
19
+ @app.call(env)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ CREATOR_SUB_DOMAIN = 'creator'
26
+
27
+ def generate_path(parts, request)
28
+ path_format = '%s://%s%s'
29
+ path = parts.unshift(CREATOR_SUB_DOMAIN).join('.')
30
+
31
+ if ![80,443].include?(request.port)
32
+ path << format(':%s', request.port)
33
+ end
34
+
35
+ format(path_format, request.scheme, path, request.path)
36
+ end
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jj-middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-01 00:00:00.000000000 Z
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,7 @@ files:
122
122
  - lib/jj/middleware/base.rb
123
123
  - lib/jj/middleware/onboarding.rb
124
124
  - lib/jj/middleware/session.rb
125
+ - lib/jj/middleware/username_correction.rb
125
126
  homepage: ''
126
127
  licenses: []
127
128
  metadata: {}