Gollum via Rack

Dawa Ometto edited this page Sep 17, 2018 · 4 revisions

You can also run gollum with any rack-compatible server by placing this config.ru file inside your wiki repository. This allows you to utilize any Rack middleware like Rack::Auth, OmniAuth, etc.

#!/usr/bin/env ruby
require 'rubygems'
require 'gollum/app'

gollum_path = File.expand_path(File.dirname(__FILE__)) # CHANGE THIS TO POINT TO YOUR OWN WIKI REPO
wiki_options = {:universal_toc => false}
Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:default_markup, :markdown) # set your favorite markup language
Precious::App.set(:wiki_options, wiki_options)
run Precious::App

Your Rack middleware can pass author details to Gollum in a Hash in the session under the gollum.author key.

The options hash

The options available for the :wiki_options hash mostly correspond to the arguments used when running gollum from the command line, but there are some small exceptions. Below is a list of the keys you can use to set gollum's options when running it as a Rack app.

wiki_options = {}
wiki_options[:css] = true # Equivalent to --css
wiki_options[:js] = true # Equivalent to --js
wiki_options[:template_dir] = path # Equivalent to --template-dir
wiki_options[:page_file_dir] = path # Equivalent to --page-file-dir
wiki_options[:gollum_path] = path # Equivalent to ARGV
wiki_options[:ref] = ref ## Equivalent to --ref
wiki_options[:repo_is_bare] = true # Equivalent to --bare
wiki_options[:allow_editing] = false # # Equivalent to --no-edit
wiki_options[:live_preview] = true # Equivalent to --live-preview
wiki_options[:allow_uploads] = true # Equivalent to --allow-uploads
wiki_options[:per_page_uploads] = true # When :allow_uploads is set, store uploads under a directory named after the page, as when using --allow-uploads page
wiki_options[:mathjax] = true # Equivalent to --mathjax
wiki_options[:mathjax_config] = source # Equivalent to --mathjax-config
wiki_options[:user_icons] = source # Equivalent to --user-icons
wiki_options[:show_all] = true # Equivalent to --show-all
wiki_options[:collapse_tree] = true # Equivalent to --collapse-tree
wiki_options[:h1_title] = true # Equivalent to --h1-title

The --base-path option

The --base-path option has no equivalent in the options hash. This is because base path is implemented as a piece of middleware, which you will have to add to your config.ru manually. Here is the code for this middleware from bin/gollum:

require 'rack'

class MapGollum
    def initialize base_path
        @mg = Rack::Builder.new do
            map '/' do
                run Proc.new { [302, { 'Location' => "/#{base_path}" }, []] }
            map "/#{base_path}" do
                run Precious::App

    def call(env)

# Rack::Handler does not work with Ctrl + C. Use Rack::Server instead.
Rack::Server.new(:app => MapGollum.new('wiki'), :Port => options['port'], :Host => options['bind']).start

Please note: when using this setup, the run Precious::App line from the example config.ru at the top of this page becomes superfluous.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.