jj-middleware 3.0.3 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jj/middleware.rb +1 -1
- data/lib/jj/middleware/username_correction.rb +39 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f317b5db82cca5c4c981ce143646ae2eef4fb19
|
4
|
+
data.tar.gz: 362f85b29caee84acc3384d70966b12684a3560d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1967d1c2f795f0e899cec64e829a908c0c80c391e5f95c91fee2e8fbf78e2a891b01144b5700cb2aacded60c4686bdd0cc1525c69131caab8d9d792fcf56faf
|
7
|
+
data.tar.gz: 1325358a38bf6cb0392e26de2d1fdbe3001b25373c25e13565b66cd2fabe291edd60e09d24db4c3e865e51b5205c84520b00fd91d123f8ebe25fc896a9751d86
|
data/lib/jj/middleware.rb
CHANGED
@@ -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
|
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-
|
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: {}
|