redirectly 0.1.1 → 0.1.2
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 +4 -4
- data/bin/redirectly +5 -8
- data/lib/redirectly/app.rb +53 -26
- data/lib/redirectly/cli.rb +1 -1
- data/lib/redirectly/command.rb +17 -18
- data/lib/redirectly/version.rb +1 -1
- data/lib/redirectly.rb +4 -4
- metadata +30 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d11d303417a59a9ef3a9fd2c970233c31d2810ae52ca945600bd42ee129c8d5a
|
4
|
+
data.tar.gz: 82076365bdb96e6486a099573155fba968ddf2d6a03a6b1547d72afcb903bf7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8edef52f11f59f8f06cd76b36e9d7d8e293620f8e49c94183895c643c74d2d399b228a3a4b39b713e0cbc3b8d7a4e33aaeaac6c6b5e8ceac3f831b1642e6cb7a
|
7
|
+
data.tar.gz: 95cbace8f96efe12fa38f08347fd4565b7ab68c798829bcf39bd0919d2f99906a218474c73867fce9d726ebe8ca0fa0e7d0f5d24d5dcca17a4ceaa966ec56633
|
data/bin/redirectly
CHANGED
@@ -8,18 +8,15 @@ router = Redirectly::CLI.router
|
|
8
8
|
|
9
9
|
begin
|
10
10
|
exit router.run ARGV
|
11
|
-
|
12
11
|
rescue Interrupt
|
13
12
|
say "\nGoodbye"
|
14
|
-
exit 1
|
15
|
-
|
13
|
+
exit 1
|
16
14
|
rescue => e
|
17
15
|
if ENV['DEBUG']
|
18
|
-
puts e.backtrace.reverse
|
19
|
-
say
|
16
|
+
puts e.backtrace.reverse
|
17
|
+
say ''
|
20
18
|
end
|
21
|
-
say "
|
19
|
+
say "ru`ERROR: #{e.class}`"
|
22
20
|
say e.message
|
23
21
|
exit 1
|
24
|
-
|
25
|
-
end
|
22
|
+
end
|
data/lib/redirectly/app.rb
CHANGED
@@ -6,58 +6,85 @@ module Redirectly
|
|
6
6
|
class App
|
7
7
|
using Refinements
|
8
8
|
|
9
|
-
attr_reader :config_path
|
9
|
+
attr_reader :config_path, :req
|
10
10
|
|
11
11
|
def initialize(config_path)
|
12
12
|
@config_path = config_path
|
13
13
|
end
|
14
14
|
|
15
15
|
def call(env)
|
16
|
-
req = Rack::Request.new
|
17
|
-
found = match
|
16
|
+
@req = Rack::Request.new env
|
17
|
+
found = match
|
18
18
|
|
19
19
|
if found
|
20
|
-
|
21
|
-
code, target = 301, found[1..-1]
|
22
|
-
else
|
23
|
-
code, target = 302, found
|
24
|
-
end
|
25
|
-
|
26
|
-
[code, {'Location' => target}, []]
|
27
|
-
|
20
|
+
redirect_to found
|
28
21
|
else
|
29
|
-
|
30
|
-
|
22
|
+
not_found
|
31
23
|
end
|
32
24
|
end
|
33
25
|
|
34
26
|
private
|
35
27
|
|
28
|
+
def redirect_to(target)
|
29
|
+
code = 302
|
30
|
+
|
31
|
+
if target.start_with? '!'
|
32
|
+
code = 301
|
33
|
+
target = target[1..]
|
34
|
+
end
|
35
|
+
|
36
|
+
[code, { 'Location' => target }, []]
|
37
|
+
end
|
38
|
+
|
39
|
+
def not_found
|
40
|
+
[404, { 'Content-Type' => 'text/plain' }, ['Not Found']]
|
41
|
+
end
|
42
|
+
|
36
43
|
def redirects
|
37
44
|
@redirects ||= ini_read(config_path)
|
38
45
|
end
|
39
46
|
|
40
47
|
def ini_read(path)
|
41
|
-
content = File.readlines(path, chomp:true).reject
|
42
|
-
content.
|
48
|
+
content = File.readlines(path, chomp: true).reject(&:comment?)
|
49
|
+
content.to_h { |line| line.split(/\s*=\s*/, 2) }
|
43
50
|
end
|
44
51
|
|
45
|
-
def match
|
52
|
+
def match
|
46
53
|
redirects.each do |pattern, target|
|
47
|
-
|
48
|
-
|
49
|
-
matcher = Mustermann.new(pattern)
|
50
|
-
params = matcher.params(requested)
|
51
|
-
if params
|
52
|
-
params.transform_keys! &:to_sym
|
53
|
-
params.delete :splat
|
54
|
-
params.transform_values! { |v| CGI.escape v }
|
55
|
-
return target % params
|
56
|
-
end
|
54
|
+
found = find_target pattern, target
|
55
|
+
return found if found
|
57
56
|
end
|
58
57
|
|
59
58
|
nil
|
60
59
|
end
|
61
60
|
|
61
|
+
def find_target(pattern, target)
|
62
|
+
params = get_params pattern
|
63
|
+
params ? composite_target(target, params) : nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_params(pattern)
|
67
|
+
pattern = "#{pattern}/" unless pattern.include? '/'
|
68
|
+
requested = "#{req.host}#{req.path}"
|
69
|
+
matcher = Mustermann.new pattern
|
70
|
+
params = matcher.params requested
|
71
|
+
|
72
|
+
if params
|
73
|
+
params.transform_keys!(&:to_sym)
|
74
|
+
params.delete :splat
|
75
|
+
params.transform_values! { |v| CGI.escape v }
|
76
|
+
end
|
77
|
+
|
78
|
+
params
|
79
|
+
end
|
80
|
+
|
81
|
+
def composite_target(target, params)
|
82
|
+
result = target % params
|
83
|
+
unless req.query_string.empty?
|
84
|
+
glue = result.include?('?') ? '&' : '?'
|
85
|
+
result = "#{result}#{glue}#{req.query_string}"
|
86
|
+
end
|
87
|
+
result
|
88
|
+
end
|
62
89
|
end
|
63
90
|
end
|
data/lib/redirectly/cli.rb
CHANGED
data/lib/redirectly/command.rb
CHANGED
@@ -1,41 +1,39 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'colsole'
|
2
|
+
require 'mister_bin'
|
3
3
|
|
4
4
|
module Redirectly
|
5
5
|
class Command < MisterBin::Command
|
6
6
|
include Colsole
|
7
|
-
help
|
7
|
+
help 'Start the redirect server'
|
8
8
|
version Redirectly::VERSION
|
9
9
|
|
10
|
-
usage
|
11
|
-
usage
|
12
|
-
usage
|
10
|
+
usage 'redirectly [CONFIG --port PORT]'
|
11
|
+
usage 'redirectly --init'
|
12
|
+
usage 'redirectly --help | --version'
|
13
13
|
|
14
|
-
option
|
15
|
-
option
|
14
|
+
option '-p --port PORT', 'Listening port [default: 3000]'
|
15
|
+
option '-i --init', 'Create a sample config file and exit'
|
16
16
|
|
17
|
-
param
|
17
|
+
param 'CONFIG', 'Path to config file [default: redirects.ini]'
|
18
18
|
|
19
|
-
example
|
20
|
-
example
|
19
|
+
example 'redirectly --init'
|
20
|
+
example 'redirectly config.ini'
|
21
21
|
|
22
22
|
attr_reader :config_path, :port
|
23
23
|
|
24
24
|
def run
|
25
25
|
@port = args['--port'].to_i
|
26
|
-
@config_path = args['CONFIG'] ||
|
26
|
+
@config_path = args['CONFIG'] || 'redirects.ini'
|
27
27
|
args['--init'] ? init_file : start_server
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
32
|
def init_file
|
33
|
-
if File.exist? config_path
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
say "Initialized #{config_path}"
|
38
|
-
end
|
33
|
+
raise ArgumentError, "#{config_path} already exists" if File.exist? config_path
|
34
|
+
|
35
|
+
File.write config_path, template
|
36
|
+
say "Initialized #{config_path}"
|
39
37
|
end
|
40
38
|
|
41
39
|
def template
|
@@ -50,6 +48,7 @@ module Redirectly
|
|
50
48
|
|
51
49
|
def start_server
|
52
50
|
raise ArgumentError, "Cannot find config file #{config_path}" unless File.exist? config_path
|
51
|
+
|
53
52
|
Rack::Server.start(app: app, Port: port, environment: 'production')
|
54
53
|
end
|
55
54
|
|
data/lib/redirectly/version.rb
CHANGED
data/lib/redirectly.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require 'byebug' if ENV['BYEBUG']
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'redirectly/refinements'
|
4
|
+
require 'redirectly/version'
|
5
|
+
require 'redirectly/app'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redirectly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mister_bin
|
@@ -25,47 +25,59 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: mustermann
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.1'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '4'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
43
|
+
version: '1.1'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '4'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: puma
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- - "
|
51
|
+
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '5.3'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '7'
|
48
57
|
type: :runtime
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
51
60
|
requirements:
|
52
|
-
- - "
|
61
|
+
- - ">="
|
53
62
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
63
|
+
version: '5.3'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '7'
|
55
67
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
68
|
+
name: rack
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
58
70
|
requirements:
|
59
71
|
- - "~>"
|
60
72
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
73
|
+
version: '2.2'
|
62
74
|
type: :runtime
|
63
75
|
prerelease: false
|
64
76
|
version_requirements: !ruby/object:Gem::Requirement
|
65
77
|
requirements:
|
66
78
|
- - "~>"
|
67
79
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
80
|
+
version: '2.2'
|
69
81
|
description: Redirect server with dynamic URL and hostname support
|
70
82
|
email: db@dannyben.com
|
71
83
|
executables:
|
@@ -87,6 +99,7 @@ licenses:
|
|
87
99
|
metadata:
|
88
100
|
bug_tracker_uri: https://github.com/DannyBen/redirectly/issues
|
89
101
|
source_code_uri: https://github.com/dannyben/redirectly
|
102
|
+
rubygems_mfa_required: 'true'
|
90
103
|
post_install_message:
|
91
104
|
rdoc_options: []
|
92
105
|
require_paths:
|
@@ -95,14 +108,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
108
|
requirements:
|
96
109
|
- - ">="
|
97
110
|
- !ruby/object:Gem::Version
|
98
|
-
version: 2.
|
111
|
+
version: 2.6.0
|
99
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
113
|
requirements:
|
101
114
|
- - ">="
|
102
115
|
- !ruby/object:Gem::Version
|
103
116
|
version: '0'
|
104
117
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
118
|
+
rubygems_version: 3.4.8
|
106
119
|
signing_key:
|
107
120
|
specification_version: 4
|
108
121
|
summary: Redirectly redirect server
|