I recently upgraded the Middleman gem in my blog installation to the latest version, v3.4.0, and found to my dismay that it no longer worked with Pow. A refactor to Middleman::PreviewServer
caused Pow to throw a TypeError – PreviewServer is not a module
exception. The good news is that the change was a simple one, and you’ll only need to change a single word in your config.ru
file to make it work again.
Various sources from around the internet recommend that your config.ru
file look something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'rubygems'
require 'middleman-core/load_paths'
Middleman.setup_load_paths
require 'middleman-core'
require 'middleman-core/preview_server'
module Middleman::PreviewServer
def self.preview_in_rack
@options = { latency: 0.25 }
@app = new_app
start_file_watcher
end
end
Middleman::PreviewServer.preview_in_rack
run Middleman::PreviewServer.app.class.to_rack_app
And all you have to do to make Pow work again with Middleman is to change the module
keyword on line 9 to class
: PreviewServer is now a class instead of a module.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'rubygems'
require 'middleman-core/load_paths'
::Middleman.setup_load_paths
require 'middleman-core'
require 'middleman-core/preview_server'
class ::Middleman::PreviewServer
def self.preview_in_rack
@options = { latency: 0.25 }
@app = new_app
start_file_watcher
end
end
::Middleman::PreviewServer.preview_in_rack
run ::Middleman::PreviewServer.app.class.to_rack_app
Boom!