-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
97 lines (83 loc) · 2.83 KB
/
app.rb
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Step 2
class HelloWorld
def call(env)
[200, {}, ['Hello World']]
end
end
# # Step 3
# class HelloWorld
# def call(env)
# # Please, please, don't put params directly into the output
# # like this. It's not safe from hackers!
# [200, {}, ["Hello, #{env['QUERY_STRING']}"]]
# end
# end
# # Step 4
# class HelloWorld
# def call(env)
# request = Rack::Request.new env
# # Please, please, don't put params directly into the output
# # like this. It's not safe from hackers!
# [200, {}, ["Hello, #{request.params['person']}"]]
# end
# end
# # Step 5
# class HelloWorld
# def call(env)
# request = Rack::Request.new env
# # Please, please, don't open files blindly like this upon request
# # from an external user. It's not safe from hackers!
# file = File.open(request.params['q'] + '.html')
# [200, {}, file]
# end
# end
# # Step 6
# class HelloWorld
# def call(env)
# request = Rack::Request.new env
# @person = request.params['person']
# # Please, please, just don't do anything in this file. Use sinatra
# # or rails to do this stuff. They're smarter than us! :)
# file = File.open(request.params['q'] + '.html.erb')
# template = ERB.new(file.read)
# result = template.result(binding)
# [200, {}, [result]]
# end
# end
# # Step 7
# class HelloWorld
# def call(env)
# request = Rack::Request.new env
# @person = request.params['person']
# # This one is actually pretty safe. As we go up to higher-level and
# # more complex gems they start to do more things like sanitization.
# file = request.params['q'] + '.md'
# require 'github/markup'
# @page = GitHub::Markup.render(file, File.open(file).read)
# # Please, please, just don't do anything in this file. Use sinatra
# # or rails to do this stuff. They're smarter than us! :)
# layout = File.open('layout.html.erb')
# template = ERB.new(layout.read)
# result = template.result(binding)
# [200, {}, [result]]
# end
# end
# # Step 8
# class HelloWorld
# def call(env)
# # Initial creation steps ("caching")
# # Make a request object
# # Find params, sanitize them and pass them to a template tool like
# # markdown or ERB or github-markup
# # Make the layout, pass in the page object we just created
# # Save the plain html file to a folder named something like _site
# # Now we just need to go back to HelloWorld4
# # Or even better, use Apache or Nginx which are /much/ better at
# # serving plain html pages.
# # This is called caching, but we could do this without requesting
# # webpages at all. This is what `jekyll build` does. So all you get
# # is plain html pages with no need to boot a ruby server at all. This
# # is what github-pages does (ie: username.github.io)
# [200, {}, ['']]
# end
# end