ローファイ日記

出てくるコード片、ぼくが書いたものは断りがない場合 MIT License としています http://udzura.mit-license.org/

Uzumibi 0.3 のリリース

リリースした。往生際悪く(?)ブログを書く。


github.com

Xの通りだが、以下のようなパラメータ入りのルーティングにも対応した(そのために Adaptive Radix Tree ベースのルーターを自作した)し、あと post "hogehoge" do などと書けるようになってる。

class App < Uzumibi::Router
  get "/" do |req, res|
    res.status_code = 200
    res.headers = {
      "content-type" => "text/plain",
      "x-powered-by" => "#{RUBY_ENGINE} #{RUBY_VERSION}"
    }
    res.body = "It works!\nVisit /greet/to/:name to get greeted.\n"
    res
  end

  get "/description" do |req, res|
    res.status_code = 200
    res.headers = {
      "content-type" => "text/plain",
    }
    res.body = 
      "\"Uzumibi\" is a Japanese term that refers\n" +
      "to live embers buried under a layer of ash\n" +
      "to keep the fire from going out.\n"
    res
  end

  get "/greet/to/:name" do |req, res|
    res.status_code = 200
    res.headers = {
      "content-type" => "text/plain",
      "x-powered-by" => "#{RUBY_ENGINE} #{RUBY_VERSION}"
    }
    res.body = "Hello, #{req.params[:name]}!!\n"
    res
  end

  get "/hello/:name" do |req, res|
    res.status_code = 302
    res.headers = {
      "location" => "/greet/to/#{req.params[:name]}",
      "content-type" => "text/plain",
    }
    res.body = "Moved\n"
    res
  end
end

$APP = App.new

ちゃんとrequest bodyも req.body でアクセスできる。あと application/x-www-form-urlencoded なら自動で params にも展開してくれるようにした。

ところでまだインタフェースは変わるかも知れねぇ...。 use App とかの方がかっこいいのかな?とか。ちょっとの違いだけど...。


しかし、まともに動き出すと、どんどん機能の足りなさが気になってくる。

  • もうちょっと例外処理をまともにしたい
  • Cloud Run実装は普通のサーバなので、 uzumibi-hyper を切り出したい。
  • uzumibi-hyper を使ってAWS Lambda対応等をしたい。
  • 各プラットフォーム固有のストレージその他をそろそろ使いたい。慣れてるGoogle Cloudからやるかな...。
  • 各テンプレートでできるプロジェクトがちゃんと動くことを自動テストしたい。ついに Runn 、使っちゃおうかな。
  • そもそもmruby/edgeが全然機能足りてねぇ...

ちなみに0.3では、Cloudflareテンプレートで作られるArtifactのサイズは:

 ⛅️ wrangler 4.60.0
───────────────────
Total Upload: 417.51 KiB / gzip: 130.69 KiB

徐々に増えてきたが、まだまだ余裕っす...。

機能が揃ったら、Artifactのサイズもよりいい感じにすることを考えたい。


ということでUzumibi、試してみてね。

$ cargo install uzumibi-cli@0.3.0 
$ uzumibi new -t cloudflare sample-app

あとはinstructionが表示されるので従うだけです。