-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
35 lines (27 loc) · 1011 Bytes
/
app.rb
File metadata and controls
35 lines (27 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'dotenv';Dotenv.load
require 'spy_glass'
proxy = SpyGlass::Proxy.new ENV.fetch('HOST') do |config|
config.content_type = 'application/json'
config.define_parser { |body| JSON.parse(body) }
config.define_generator { |body| JSON.pretty_generate(body) }
config.cache = ActiveSupport::Cache::MemoryStore.new(expires_in: Integer(ENV['CACHE_TTL'] || 5.minutes))
config.define_transformation do |collection|
features = collection.map do |record|
longitude = record['longitude'] || (record['point'] && record['point']['longitude'])
latitude = record['latitude'] || (record['point'] && record['point']['latitude'])
{ 'type' => 'Feature',
'properties' => record,
'geometry' => {
'type' => 'Point',
'coordinates' => [
longitude.to_f,
latitude.to_f ] } }
end
{ 'type' => 'FeatureCollection', 'features' => features }
end
end
require 'sinatra'
get '/' do
erb :index
end
get('*', provides: :json, &proxy)