h2o web serverのmrubyを使ってみる
spa(single page application)のindex.htmlをh2oで配布する際どうすりゃいいのか。
vueとかのspaだと、vue-routerとかつかってルーティングするため、
http://xxx.com/aaa/bbb/ccc
でアクセスしたときも、index.html
を返却して、その中でjsを解釈してルーティングをする。
h2oでindex.htmlを配布するさい、どうすりゃいいのかわからなかった。
nginxだとtry_files
とかいうので対応できるみたい。
h2oはmrubyでフック処理をかけるので、それで簡単に対応できたけど、本番環境だと、他にいろいろ考慮しなければいけない感じがする。
runitで動かしてるのでファイル指定などは相対パスにしてる。
listen:
port: 8000
hosts:
"0.0.0.0":
paths:
/:
mruby.handler-file: './forspa.rb'
file.dir: /tmp/somewhere
./forspa.rbの内容。
path = "/tmp/somewhere"
cont = File.open("#{path}/index.html").read()
lambda do |env|
unless File.exist?("#{path}/" + env["PATH_INFO"])
return [200, {'content-type' => 'text/html'}, [cont]]
end
return [399, {}, []]
end
Author And Source
この問題について(h2o web serverのmrubyを使ってみる), 我々は、より多くの情報をここで見つけました https://qiita.com/dice-k-nakatani/items/9ba24e8390ea97804bc2著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .