Problem serving local files
serge-hulne opened this issue · comments
Description
- Problem serving local files.
- I tried the code hereunder, but the local file do not seem to be served.
- Perhaps my minimalist server is missing an instruction linking the local files to a given route ?
Steps to Reproduce
- Code for the server
require "kemal"
IP = "127.0.0.1"
PORT = 8081
Kemal.config.port = (ENV["PORT"]? || PORT).to_i
Kemal.config.host_binding = ENV["HOST_BINDING"]? || "#{IP}"
# Kemal.config.env = "production"
Kemal.run do |config|
config.public_folder = "dist"
end
- Compile and run 1.
Expected behavior:
I would expect that when te browser points to http://127.0.0.1:8081/
or http://127.0.0.1:8081/index.html
, the content of said index.html page is displayed in the browser.
Actual behavior: Instead, I get:
Reproduces how often:
Systematic
Versions
- Crystal 1.6.0 (2022-10-06)
- Hardware Mac M1
Additional Information
Any additional information, configuration or data that might be necessary to reproduce the issue.
It works if public_folder
function is used instead of setting in config. Will try to dig more and get the exact reason for this. For now you can try
require "kemal"
IP = "127.0.0.1"
PORT = 8081
Kemal.config.port = (ENV["PORT"]? || PORT).to_i
Kemal.config.host_binding = ENV["HOST_BINDING"]? || "#{IP}"
# Kemal.config.env = "production"
public_folder "dist"
Kemal.run do |config|
# other configs ...
end
Thank you!
Hi @serge-hulne . Please re-open the issue. It's just a workaround.
This code is not working as expected::
Kemal.run do |config|
config.public_folder = "dist"
end
The original issue can be fixed in Kemal by placing yield config
right above config.setup
here:
https://github.com/kemalcr/kemal/blob/master/src/kemal.cr#L32-L47
/cc @aravindavk
The original issue can be fixed in Kemal by placing yield config right above config.setup here:
Thanks for the pointer. Are you planning to send the fix, or shall I send?
@aravindavk nope. Please check if it actually fixes the issue. Because I'm not sure. And create PR. Thanks.