-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ru
72 lines (52 loc) · 1.53 KB
/
config.ru
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require 'sinatra'
require 'grape'
require "appsignal/integrations/sinatra"
require "appsignal/integrations/grape"
require "sequel"
Sequel::Database.register_extension(
:appsignal_integration,
Appsignal::Hooks::SequelLogConnectionExtension
)
Sequel::Database.extension(:appsignal_integration)
# connect to an in-memory database
DB = Sequel.sqlite
# create an items table
DB.create_table :items do
primary_key :id
String :name, unique: true, null: false
Float :price, null: false
end
class Web < Sinatra::Base
get '/' do
# create a dataset from the items table
items = DB[:items]
# populate the table
items.insert(name: 'a1', price: rand * 100)
items.insert(name: 'a2', price: rand * 100)
items.insert(name: 'a3', price: rand * 100)
# print out the number of records
puts "Item count: #{items.count}"
# print out the average price
puts "The average price is: #{items.avg(:price)}"
'Hello world.'
end
end
class API < Grape::API
insert_before Grape::Middleware::Error, Appsignal::Grape::Middleware
prefix "api"
format :json
get :hello do
items = DB[:items]
# populate the table
items.insert(name: 'b1', price: rand * 100)
items.insert(name: 'b2', price: rand * 100)
items.insert(name: 'b3', price: rand * 100)
# print out the number of records
puts "Item count: #{items.count}"
# print out the average price
puts "The average price is: #{items.avg(:price)}"
{ hello: 'world' }
end
end
use Rack::Session::Cookie
run Rack::Cascade.new [Web, API]