【问题标题】:404 GET / When index.html is available404 GET / 当 index.html 可用时
【发布时间】:2017-03-25 00:33:38
【问题描述】:

我正在尝试使用 Kemal 在 Crystal 中编写一个简单的静态站点。

通过this page,我应该没问题,但是当我尝试加载网站时收到 404。

我的程序看起来像这样(你可以看到我注释掉的所有代码试图追踪问题)

#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

这是我的目录结构:

.
├── 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

【问题讨论】:

    标签: crystal-lang kemal


    【解决方案1】:

    这里是凯末尔作者。

    默认情况下,Kemal 不会将 index.html 用作 /。但是,您可以使用redirect

    来实现
    get "/" do |env|
      env.redirect "index.html"
    end
    

    【讨论】:

    • 我在几秒钟内就可以发布关于此的问题。谢谢!
    猜你喜欢
    • 2021-11-18
    • 1970-01-01
    • 2012-03-29
    • 2017-03-05
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多