Search code examples
crystal-langkemal

404 GET / When index.html is available


I'm trying to write a simple static site in Crystal using Kemal.

Going by this page, I should be fine, but I get a 404 when I try to load the site.

My program looks like this (you can see all the code I commented out trying to track the issue down)

#require "./LiedThisWeek/*"
require "kemal"

#module LiedThisWeek
  # TODO Put your code here
#end

#finder = LieFinder.new
#handler = HyperTextHandler.new finder
#indexPath = "public/index.html"
#
#spawn do
#   loop do
#       finder.refresh
#       File.write indexPath, handler.getDoc
#       sleep 60.second
#   end
#end

Kemal.run

This is what my directory structure looks like:

.
├── LICENSE
├── LiedThisWeek
├── README.md
├── lib (removed for brevity)
├── public
│   ├── css
│   │   └── style.css
│   ├── images
│   │   ├── fireworks.jpg
│   │   └── sad.jpg
│   └── index.html
├── shard.lock
├── shard.yml
├── spec
│   ├── LiedThisWeek_spec.cr
│   └── spec_helper.cr
└── src
    ├── LiedThisWeek
    │   ├── HyperTextHandler.cr
    │   ├── Lie.cr
    │   ├── LieFinder.cr
    │   └── version.cr
    └── LiedThisWeek.cr

32 directories, 112 files

Solution

  • Kemal author here.

    Kemal doesn't serve index.html as / by default. However you can achieve that with a redirect

    get "/" do |env|
      env.redirect "index.html"
    end