-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support setting routes for serving static files #64
Conversation
It can work as expected now but with unhandled errors.
|
Can you investigate why does this happen? |
Relevant issue: crystal-lang/crystal#14566 |
Should be fixed by #66 |
The code works well now and is reviewable. |
@yanecc Can you provide an example? |
I am going to modify this code a little bit to be a bit more Grip-esque, I will update the documentation with the news. |
Sure, here is a simple illustration. class Application < Grip::Application
def initialize()
super(environment: "development", serve_static: true)
end
getter host : String = "127.0.0.1"
# getter pubilc_dir : String = "./public"
getter static_routes : Hash(String, String) = {
# "/" => "./public",
"/foo/bar" => "./dir1",
"/baz" => "./path/to/dir2",
}
end
# By default, when serve_static is set to true, public_dir will be set to "./public".
# You could use pubilc_dir to set the static directory.
# If static_routes is set, pubilc_dir will be overwritten.
# GET http://127.0.0.1 #=> 404 Not Found
# GET http://127.0.0.1/foo/bar #=> 200 OK -> ./dir1/index.html
# GET http://127.0.0.1/baz #=> 200 OK -> ./path/to/dir2/index.html |
I updated the version of Grip to 3.0.0 since I implemented breaking changes and will update the documentation to reflect your changes as well, added a new DSL macro. |
@yanecc Added the documentation, check it out. |
Looks good. 👍 |
This is a work in progress, aiming to address #60
There is still much work to do ...