質問編集履歴

1

追記しました

2015/04/23 03:37

投稿

hfhff
hfhff

スコア8

test CHANGED
File without changes
test CHANGED
@@ -121,3 +121,117 @@
121
121
  </html>
122
122
 
123
123
  ```
124
+
125
+
126
+
127
+ 追記です
128
+
129
+ erbを使いたかったのとかなり前のプログラムだったので付録(デフォルト)のwebrickでは無く自前のwebrickを書いたのですがそれが原因の気がします...
130
+
131
+ ```lang-<ruby>
132
+
133
+ ##myserver.rb(自前)
134
+
135
+ require 'webrick'
136
+
137
+
138
+
139
+ config = {
140
+
141
+ :Port => 8099,
142
+
143
+ :DocumentRoot => './',
144
+
145
+ }
146
+
147
+
148
+
149
+ WEBrick::HTTPServlet::FileHandler.add_handler("erb", WEBrick::HTTPServlet::ERBHandler)
150
+
151
+
152
+
153
+ server = WEBrick::HTTPServer.new(config)
154
+
155
+
156
+
157
+ server.config[:MimeTypes]["erb"] = "text/html"
158
+
159
+
160
+
161
+ trap(:INT) do
162
+
163
+ server.shutdown
164
+
165
+ end
166
+
167
+
168
+
169
+ server.start
170
+
171
+ ```
172
+
173
+ ##server.rb(デフォルト)
174
+
175
+ ```lang-<ruby>
176
+
177
+ require 'webrick'
178
+
179
+
180
+
181
+ rrr = WEBrick::HTTPServlet::CGIHandler::Ruby
182
+
183
+ $ruby = $ruby || rrr
184
+
185
+
186
+
187
+ module WEBrick
188
+
189
+ module HTTPServlet
190
+
191
+ FileHandler.add_handler("rb", CGIHandler)
192
+
193
+ end
194
+
195
+ end
196
+
197
+
198
+
199
+ def start_webrick(config = {})
200
+
201
+ conf = {
202
+
203
+ :Port => 8080,
204
+
205
+ :BindAddress => '127.0.0.1',
206
+
207
+ :CGIInterpreter => $ruby,
208
+
209
+ }
210
+
211
+ config.update(conf)
212
+
213
+ server = WEBrick::HTTPServer.new(config)
214
+
215
+ yield server if block_given?
216
+
217
+ ['INT', 'TERM'].each {|signal|
218
+
219
+ trap(signal) {server.shutdown}
220
+
221
+ }
222
+
223
+ server.start
224
+
225
+ end
226
+
227
+
228
+
229
+ start_webrick {|server|
230
+
231
+ cgi_dir = File.dirname( File.expand_path(__FILE__) )
232
+
233
+ server.mount("/", WEBrick::HTTPServlet::FileHandler, cgi_dir, {:FancyIndexing=>true})
234
+
235
+ }
236
+
237
+ ```