forked from otobrglez/webruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter7.html
112 lines (95 loc) · 3.65 KB
/
chapter7.html
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!doctype html>
<html>
<head>
<title>Programming for the Web with Ruby</title>
<meta charset="utf-8">
<meta name="author" content="Satish Talim" >
<meta name="keywords" content="programming, Ruby, Rack, Sinatra" >
<meta name="description" content="A Ruby programming tutorial on topics that hopefully will help those that have some knowledge of Ruby programming to get started with web programming." >
<link rel="stylesheet" href="stylesheets/intruby.css">
</head>
<body>
<div>
<p>
<strong>
<a href="chapter6.html"><Chapter 6 | </a>
<a href="toc.html">TOC | </a>
<a href="chapter8.html">Chapter 8></a>
</strong>
</p>
<h1 class="title">Day 8</h1>
<h2>Deploying a static webpage to Heroku</h2>
<p>We have already created a simple webpage before and the related files are in the folders as shown below:</p>
<pre>- DosaSite
|- config.ru
|- public
|- index.html
|- stylesheets
|- images
</pre>
<p>In <code>config.ru</code> file add the following:</p>
<pre>use Rack::Static,
:urls => ["/stylesheets", "/images"],
:root => "public"
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY)
]
}
</pre>
<p>This assumes that your template uses relative references to the images and stylesheets.</p>
<p><b>Note</b>: In case you have other .html files in your <code>public</code> folder like chapter1.html and chapter2.html, then change the above code as follows:</p>
<pre>use Rack::Static,
:urls => ["/stylesheets", "/images", "/chapter1.html", "/chapter2.html"],
:root => "public"
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY)
]
}
</pre>
<p>All Heroku apps are fronted by <code>Varnish</code>, an HTTP Accelerator, and we should take advantage of it. You may have noticed in the <code>config.ru</code> file we set the <code>Cache-Control</code> header to 86400 seconds (24 hours). This tells the accelerator to go ahead and cache the page. The accelerator already caches any <code>Rack::File</code> for 12 hours as well meaning all your stylesheets and images will also be cached.</p>
<p>Open a Bash shell in the folder <code>DosaSite</code> and type:</p>
<pre>$ git add .
$ git commit -m "first commit to Heroku"
</pre>
<p>Let's create our Rack app on Heroku. Type:</p>
<pre>$ heroku create
Creating falling-fire-2394... done, stack is bamboo-mri-1.9.2
http://falling-fire-2394.heroku.com/ | [email protected]:falling-fire-2394.git
Git remote heroku added
</pre>
<p>Now let us deploy our code to Heroku. Type:</p>
<pre>$ git push heroku master
</pre>
<p>At this stage we can rename our app to <code>dosasite</code>. Type:
<pre>$ heroku rename dosasite
http://dosasite.heroku.com/ | [email protected]:dosasite.git
Git remote heroku updated
</pre>
<p>Our app is now deployed to Heroku. Open a new browser window and type <a href="http://dosasite.heroku.com/">http://dosasite.heroku.com/</a>. You should see our simple webpage.</p>
<h2>Exercise: Deploy your static site to Heroku</h2>
<p>Previously, you have already created a single html page about yourself. Deploy this to Heroku and post the URL of your site in the technical forum.</p>
<p>
<strong>
<a href="chapter6.html"><Chapter 6 | </a>
<a href="toc.html">TOC | </a>
<a href="chapter8.html">Chapter 8></a>
</strong>
</p>
<div id="footer">
<p>© 2006-2012 <strong>RubyLearning.org - Programming for the Web with Ruby</strong> Page Updated: 21st Jan. 2012</p>
</div>
</div>
</body>
</html>