This repository was archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.rb
More file actions
67 lines (56 loc) · 1.53 KB
/
server.rb
File metadata and controls
67 lines (56 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'nokogiri'
require 'sinatra'
def generate_routes src
routes = []
src.each_line do |line|
from, to = line.split(/\s+/)
from.gsub!(/\A\//, '')
to.gsub!(/\/\z/, '/index.html')
to.gsub!(/\A\//, '')
routes << { :from => from, :to => to }
end
builder = Nokogiri::XML::Builder.new do |xml|
xml.RoutingRules {
routes.each do |route|
xml.RoutingRule {
xml.Condition {
xml.KeyPrefixEquals route[:from]
}
xml.Redirect {
xml.ReplaceKeyWith route[:to]
}
}
end
}
end
builder.to_xml
end
get '/' do
"
<html>
<head>
<title>Amazon S3 Redirector</title>
</head>
<body>
<h1>Generate redirect rules for Amazon S3</h1>
<p>This is opensource <a href='https://github.com/rainforestapp/amazon-s3-redirects'>on github</a> by <a href='https://www.rainforestqa.com/'>Rainforest QA</a> from the <a href='https://gist.github.com/chitsaou/5319661'>original gist</a> by <a href='https://github.com/chitsaou'>chitsaou</a>.
<p>Example:
<pre>
/home /
/products/iphone/specs.html /iphone/specs.html
/products/iphone/ /iphone/
/products/ipad/accessories/ /ipad/accessories.html
/products/ipad/ /ipad/
/products /
</pre>
<p>Paste your stuff in here:
<form method='post'>
<p><textarea name='text' cols=80 rows=8></textarea>
<p><input type='submit' value='Give me the XML'>
</form>
"
end
post '/' do
content_type 'text/plain'
generate_routes(params['text'])
end