-
-
Save xmonader/e791491b3e67d9fbd62e383cc2bed282 to your computer and use it in GitHub Desktop.
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
# Matches /hello/kemal | |
require "kemal" | |
module TfWiki | |
module WikiServer | |
awalker = TfWiki::Walker.new | |
awikipath = "" | |
def self.walker | |
# p awalker | |
awalker | |
end | |
def self.wikipath | |
awikipath | |
end | |
def self.send_from_dirsinfo(env, filename) | |
if self.walker.dirsfilesinfo.has_key?(filename) | |
firstpath = self.walker.dirsfilesinfo[filename].paths[0] # in decent repo it will be only 1 in this array. | |
send_file env, firstpath | |
env.response.status_code = 404 | |
env.response.print "file #{filename} doesn't exist in scanned info." | |
env.response.close | |
end | |
end | |
get "/wiki/:filename" do |env| | |
puts "Got request.." | |
puts env.request.resource | |
filename = env.params.url["filename"] | |
unless filename.ends_with?(".md") | |
filename = filename + ".md" | |
end | |
self.send_from_dirsinfo(env, filename) | |
end | |
get "/:filepath" do |env| | |
puts "/:file path request " | |
puts env.request.resource | |
filepath = env.params.url["filepath"] | |
filename = File.basename(filepath) | |
unless File.exists?(filepath) | |
env.response.status_code = 404 | |
env.response.print "file #{filepath} doesn't exist." | |
env.response.close | |
end | |
self.send_from_dirsinfo(env, filename) | |
end | |
def self.setup(wikipath : String, walker : TfWiki::Walker) | |
awikipath = wikipath | |
awalker = walker | |
puts "created server.." | |
end | |
def self.serve | |
puts "Starting kemal server" | |
Kemal.run | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment