3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/port_map/mappings.rb', line 3
def self.parse_conf(filename)
contents = File.new(filename).read
server_name = contents.match(/server_name\s+(.+?);/)
location_mappings = contents.scan(/location\s+(.+?)\s+{\s+proxy_pass\s+(.+?);\s+}/m)
data = {}
data[:name] = File.basename(filename, '.port_map.conf')
data[:nginx_conf] = PortMap::Nginx.servers_directory + File::Separator + data[:name] + '.port_map.conf'
data[:server_name] = server_name.captures.first
data[:locations] = location_mappings.map do |location_mapping|
{ name: location_mapping.first, proxy_pass: location_mapping.last }
end
data
end
|