forked from getmango/Mango
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- when building for release, embed the static files in binary
- Loading branch information
1 parent
0c177c3
commit 21fcde9
Showing
6 changed files
with
47 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require "baked_file_system" | ||
require "kemal" | ||
require "gzip" | ||
require "./util" | ||
|
||
class FS | ||
extend BakedFileSystem | ||
bake_folder "../public" | ||
end | ||
|
||
class StaticHandler < Kemal::Handler | ||
property dirs : Array(String) | ||
|
||
def initialize | ||
@dirs = ["/css", "/js"] | ||
end | ||
|
||
def call(env) | ||
if request_path_startswith env, @dirs | ||
file = FS.get? env.request.path | ||
return call_next env if file.nil? | ||
|
||
slice = Bytes.new file.size | ||
file.read slice | ||
return send_file env, slice, file.mime_type | ||
end | ||
call_next env | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters