Skip to content

Instantly share code, notes, and snippets.

@zarelit
Forked from jimfoltz/tw5-server.rb
Created June 7, 2020 16:34
Show Gist options
  • Save zarelit/7320cc62f11d4225c0973fc013b167e0 to your computer and use it in GitHub Desktop.
Save zarelit/7320cc62f11d4225c0973fc013b167e0 to your computer and use it in GitHub Desktop.
A local server for TiddlyWiki5 that allows saving wiki.
require 'webrick'
module WEBrick
module HTTPServlet
class FileHandler
alias do_PUT do_GET
end
class DefaultFileHandler
def do_PUT(req, res)
file = "#{@config[:DocumentRoot]}#{req.path}"
#req.body {|buf| c << buf}
res.body = ''
#File.open(file, "w+") {|f| f.puts(c)}
File.open(file, "w+") {|f| f.puts(req.body)}
end
def do_OPTIONS(req, res)
res['allow'] = "GET,HEAD,POST,OPTIONS,CONNECT,PUT,DAV,dav"
res['x-api-access-type'] = 'file'
res['dav'] = 'tw5/put'
end
end
end
end
#sRoot = "#{Dir.pwd}/html"
sRoot = "#{Dir.pwd}"
server = WEBrick::HTTPServer.new({:Port => 8000, :DocumentRoot => sRoot})
trap "INT" do server.shutdown end
server.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment