Vikaton
Vikaton

Reputation: 2407

Static File serving using Rack

I have this block of code:

require "cuba"
require "mote"
require "mote/render"

Cuba.plugin(Mote::Render)

Cuba.use Rack::Static,
 # urls: %w[/index],
  root: File.expand_path("./public", __dir__)

Cuba.define do
  on(root) do
      render("index", title: "Welcome")
  end

end

and I'm trying to server the file in the public folder(which is in the same directory as the this file I'm running) named "index.html", but I'm getting an error on my website saying it cannot be found.

No such file or directory @ rb_sysopen - /root/views/index.html.mote

Any help? Thanks in advance!

Upvotes: 0

Views: 715

Answers (2)

Matthew Billie
Matthew Billie

Reputation: 21

You can also set up your own custom routes for serving css/js without using Rack::Static

on 'css', extension('css') do
    res['Content-Type'] = 'text/css'
    res.write File.read(req.path)
end

Upvotes: 1

Eugene Petrov
Eugene Petrov

Reputation: 1598

Cuba tries to render a template, so you can rename your file to .mote and it should render ok, or use something like this:

res.headers["Content-Type"] = "text/html; charset=utf-8"
res.write(IO.read('/path/to/your/file.html'))

Source is pretty clear on how the render function works.

Upvotes: 2

Related Questions