redirectly 0.1.1 → 0.2.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 +4 -4
- data/README.md +2 -2
- data/bin/redirectly +5 -8
- data/lib/redirectly/app.rb +53 -26
- data/lib/redirectly/cli.rb +1 -1
- data/lib/redirectly/command.rb +20 -20
- data/lib/redirectly/version.rb +1 -1
- data/lib/redirectly.rb +4 -4
- metadata +45 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dee36588a0b7625818f348fdaa4afefa27e0f16c1987a5656dd70397114d4989
|
4
|
+
data.tar.gz: 3e6a9704b9cfd7730d13d84002add38e2d350b6409176833d8861e7e3489f567
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 205afe31c98f93b7269f95fc6ebac5729c5070107547e5ff8d160ed5de742f67e633c14ab7072bf5328b9bc4968fa73b0bbca7a9e520b747b63d49409c5b2678
|
7
|
+
data.tar.gz: 7115a8ae99fb4a59b18a198851f10266035504f9473aa06cf85dd8ef26b5fd9723990d957b2263a628405f504a90fff8125a54acfe61b192c0697eba0fdc47b0
|
data/README.md
CHANGED
@@ -64,7 +64,7 @@ $ redirectly --init
|
|
64
64
|
$ redirectly
|
65
65
|
|
66
66
|
# In another terminal, access the server using one of the configured rules
|
67
|
-
$ curl -v something.
|
67
|
+
$ curl -v something.localhost:3000
|
68
68
|
```
|
69
69
|
|
70
70
|
You should receive a redirect header:
|
@@ -94,7 +94,7 @@ example.com = https://other-site.com/
|
|
94
94
|
*.mygoogle.com/:anything = https://google.com/?q=%{anything}
|
95
95
|
example.org/* = https://other-site.com/
|
96
96
|
*.old-site.com = !https://permanent.redirect.com
|
97
|
-
:sub.
|
97
|
+
:sub.app.localhost/* = http://it-works.com/%{sub}
|
98
98
|
```
|
99
99
|
|
100
100
|
For additional server options, see:
|
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,40 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'colsole'
|
2
|
+
require 'mister_bin'
|
3
|
+
require 'rackup'
|
3
4
|
|
4
5
|
module Redirectly
|
5
6
|
class Command < MisterBin::Command
|
6
7
|
include Colsole
|
7
|
-
help
|
8
|
+
help 'Start the redirect server'
|
8
9
|
version Redirectly::VERSION
|
9
10
|
|
10
|
-
usage
|
11
|
-
usage
|
12
|
-
usage
|
11
|
+
usage 'redirectly [CONFIG --port PORT]'
|
12
|
+
usage 'redirectly --init'
|
13
|
+
usage 'redirectly --help | --version'
|
13
14
|
|
14
|
-
option
|
15
|
-
option
|
15
|
+
option '-p --port PORT', 'Listening port [default: 3000]'
|
16
|
+
option '-i --init', 'Create a sample config file and exit'
|
16
17
|
|
17
|
-
param
|
18
|
+
param 'CONFIG', 'Path to config file [default: redirects.ini]'
|
18
19
|
|
19
|
-
example
|
20
|
-
example
|
20
|
+
example 'redirectly --init'
|
21
|
+
example 'redirectly config.ini'
|
21
22
|
|
22
23
|
attr_reader :config_path, :port
|
23
24
|
|
24
25
|
def run
|
25
26
|
@port = args['--port'].to_i
|
26
|
-
@config_path = args['CONFIG'] ||
|
27
|
+
@config_path = args['CONFIG'] || 'redirects.ini'
|
27
28
|
args['--init'] ? init_file : start_server
|
28
29
|
end
|
29
30
|
|
30
31
|
private
|
31
32
|
|
32
33
|
def init_file
|
33
|
-
if File.exist? config_path
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
say "Initialized #{config_path}"
|
38
|
-
end
|
34
|
+
raise ArgumentError, "#{config_path} already exists" if File.exist? config_path
|
35
|
+
|
36
|
+
File.write config_path, template
|
37
|
+
say "Initialized #{config_path}"
|
39
38
|
end
|
40
39
|
|
41
40
|
def template
|
@@ -44,13 +43,14 @@ module Redirectly
|
|
44
43
|
*.mygoogle.com/:anything = https://google.com/?q=%{anything}
|
45
44
|
example.org/* = https://other-site.com/
|
46
45
|
*.old-site.com = !https://permanent.redirect.com
|
47
|
-
:sub.
|
46
|
+
:sub.app.localhost/* = http://it-works.com/%{sub}
|
48
47
|
TEMPLATE
|
49
48
|
end
|
50
49
|
|
51
50
|
def start_server
|
52
51
|
raise ArgumentError, "Cannot find config file #{config_path}" unless File.exist? config_path
|
53
|
-
|
52
|
+
|
53
|
+
Rackup::Server.start(app: app, Port: port, environment: 'production')
|
54
54
|
end
|
55
55
|
|
56
56
|
def app
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mister_bin
|
@@ -25,47 +25,73 @@ 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
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
34
|
+
- - "<"
|
32
35
|
- !ruby/object:Gem::Version
|
33
|
-
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
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.1'
|
44
|
+
- - "<"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
46
|
+
version: '4'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: puma
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '5.3'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '7'
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '5.3'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '7'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rack
|
43
69
|
requirement: !ruby/object:Gem::Requirement
|
44
70
|
requirements:
|
45
71
|
- - "~>"
|
46
72
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
73
|
+
version: '3.0'
|
48
74
|
type: :runtime
|
49
75
|
prerelease: false
|
50
76
|
version_requirements: !ruby/object:Gem::Requirement
|
51
77
|
requirements:
|
52
78
|
- - "~>"
|
53
79
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
80
|
+
version: '3.0'
|
55
81
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
82
|
+
name: rackup
|
57
83
|
requirement: !ruby/object:Gem::Requirement
|
58
84
|
requirements:
|
59
85
|
- - "~>"
|
60
86
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
87
|
+
version: '2.1'
|
62
88
|
type: :runtime
|
63
89
|
prerelease: false
|
64
90
|
version_requirements: !ruby/object:Gem::Requirement
|
65
91
|
requirements:
|
66
92
|
- - "~>"
|
67
93
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
94
|
+
version: '2.1'
|
69
95
|
description: Redirect server with dynamic URL and hostname support
|
70
96
|
email: db@dannyben.com
|
71
97
|
executables:
|
@@ -87,7 +113,8 @@ licenses:
|
|
87
113
|
metadata:
|
88
114
|
bug_tracker_uri: https://github.com/DannyBen/redirectly/issues
|
89
115
|
source_code_uri: https://github.com/dannyben/redirectly
|
90
|
-
|
116
|
+
rubygems_mfa_required: 'true'
|
117
|
+
post_install_message:
|
91
118
|
rdoc_options: []
|
92
119
|
require_paths:
|
93
120
|
- lib
|
@@ -95,15 +122,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
122
|
requirements:
|
96
123
|
- - ">="
|
97
124
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
125
|
+
version: '3.0'
|
99
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
127
|
requirements:
|
101
128
|
- - ">="
|
102
129
|
- !ruby/object:Gem::Version
|
103
130
|
version: '0'
|
104
131
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
106
|
-
signing_key:
|
132
|
+
rubygems_version: 3.5.6
|
133
|
+
signing_key:
|
107
134
|
specification_version: 4
|
108
135
|
summary: Redirectly redirect server
|
109
136
|
test_files: []
|