rack-canonical-header 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4a2d22d823f08b477a257089f36a0847de6d2b2faefae85f203afdc8a98bde02
4
+ data.tar.gz: 98381e2a9cb18e50dd9ca3b6408a8e68815877a125be901cb03ab5001abc6a40
5
+ SHA512:
6
+ metadata.gz: f605ff888c956625e3df737478740c67369330f420e5085cb0d790715deb75e278f98408510afbd7071bcb4db0e278abeafbcee0be5392d632b409665f644dee
7
+ data.tar.gz: 70c1577a139d55e5a153fb61402f6edbc3faa18ac3c214b22faa743971bb41425cc6a77c6dbba6f83dfd533f2abe911c9540698c3148c853fcf7ab435f35ad9e
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # rack-canonical-header
2
+
3
+ Inserts a canonical url with a predefined host to prevent
4
+ search engines from crawling domains like `herokuapp.com`
5
+
6
+ ## Setup
7
+
8
+ ```
9
+ git clone git@github.com:renuo/rack-canonical-header.git
10
+ cd rack-canonical-header
11
+ bin/setup
12
+ ```
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'rack-canonical-header'
20
+ ```
21
+
22
+ And then execute `bundle install`
23
+
24
+ ## Usage
25
+
26
+ Set the `CANONICAL_HOST` env variable
27
+
28
+ ### Non-Rails frameworks
29
+
30
+ If you're using a framework which uses Rack (like Hanami)
31
+ you have to require and insert the middleware
32
+ `Canonical::Middleware` manually into the rack stack.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rdoc/task'
4
+
5
+ RDoc::Task.new(:rdoc) do |rdoc|
6
+ rdoc.rdoc_dir = 'rdoc'
7
+ rdoc.title = 'rack-canonical-header'
8
+ rdoc.options << '--line-numbers'
9
+ rdoc.rdoc_files.include('README.md')
10
+ rdoc.rdoc_files.include('lib/**/*.rb')
11
+ end
12
+
13
+ RSpec::Core::RakeTask.new(:spec)
14
+
15
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ require 'rack-canonical-header/middleware'
2
+ require 'rack-canonical-header/version'
3
+ require 'rack-canonical-header/rails' if defined?(Rails) && ENV['CANONICAL_HOST'].present?
@@ -0,0 +1,27 @@
1
+ module Canonical
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ @status, @headers, @body = nil
6
+ end
7
+
8
+ def call(env)
9
+ @status, @headers, @body = @app.call(env)
10
+ canonical_host = ENV['CANONICAL_HOST']
11
+ return [@status, @headers, @body] unless html? && canonical_host
12
+
13
+ @headers['Link'] = Middleware.canonical_tag(env, canonical_host)
14
+
15
+ [@status, @headers, @body]
16
+ end
17
+
18
+ def self.canonical_tag(env, canonical_host)
19
+ canonical = "#{env['rack.url_scheme']}://#{canonical_host}#{env['REQUEST_URI']}"
20
+ "<#{canonical}>; rel=\"canonical\""
21
+ end
22
+
23
+ def html?
24
+ @headers['Content-Type'] =~ /html/
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module Canonical
2
+ class Railtie < Rails::Railtie
3
+ initializer 'canonical.configure_rack_middleware' do |app|
4
+ app.middleware.use Canonical::Middleware
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Canonical
2
+ VERSION = '1.0.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-canonical-header
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Lukas Bischof
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mdl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: reek
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A canonical URL tag for better SEO and to prevent search engines from
112
+ crawling different hosts
113
+ email:
114
+ - lukas.bischof@renuo.ch
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - README.md
120
+ - Rakefile
121
+ - lib/rack-canonical-header.rb
122
+ - lib/rack-canonical-header/middleware.rb
123
+ - lib/rack-canonical-header/rails.rb
124
+ - lib/rack-canonical-header/version.rb
125
+ homepage: https://renuo.ch
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: 2.1.0
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.7.3
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: A gem that inserts a canonical http header
149
+ test_files: []