sinatra

where do I put code in Sinatra that I want to execute when the app is shutdown?

强颜欢笑 提交于 2021-02-08 12:52:27
问题 I am using Sinatra for my webapp. I have some cleanup code that I want to execute when my app is being shutdown. Is there a hook for this in Sinatra or do I have to use a separate mechanism? 回答1: Look at Kernel#at_exit, I don't see why it shouldn't work in a Sinatra app if you define a block like that somewhere in your main app file. Update: According to matt's comment, you have to define your at_exit handler before requiring Sinatra. 来源: https://stackoverflow.com/questions/11105556/where-do

Sinatra and Grape API together?

五迷三道 提交于 2021-02-05 20:16:32
问题 I've been reading around and I found this micro-framework called Grape for ruby. I am currently using Sinatra to handle the web interface but I would also like to implement Grape to handle the API aspect of the app. I can't find any helpful suggestions to this topic. The grape documentation says "Grape is a REST-like API micro-framework for Ruby. It's designed to run on Rack or complement existing web application frameworks such as Rails and Sinatra by providing a simple DSL to easily develop

Sinatra and Grape API together?

≡放荡痞女 提交于 2021-02-05 20:11:40
问题 I've been reading around and I found this micro-framework called Grape for ruby. I am currently using Sinatra to handle the web interface but I would also like to implement Grape to handle the API aspect of the app. I can't find any helpful suggestions to this topic. The grape documentation says "Grape is a REST-like API micro-framework for Ruby. It's designed to run on Rack or complement existing web application frameworks such as Rails and Sinatra by providing a simple DSL to easily develop

My bundler command is failing to load in my Sinatra app deployed in Heroku and thus causes it to crash

 ̄綄美尐妖づ 提交于 2021-01-28 22:20:09
问题 I am trying to successfully deploy an extremely rudimentary Sinatra app to Heroku. I am able to run this app locally. The ruby code itself is incredibly simple: require 'sinatra' get '/' do 'Hello World!' end I added a proper Gemfile: source 'https://rubygems.org' gem 'sinatra' gem 'rack' As well as a configuration file: require './hello_app' run SinatraApp This code builds successfully on Heroku: -----> Ruby app detected -----> Installing bundler 2.1.4 -----> Removing BUNDLED WITH version in

How to read a GZIP payload in Ruby Sinatra

烂漫一生 提交于 2021-01-28 12:23:10
问题 On a remote host I have a bash script sending a simple gzipped YAML file to my Ruby Sinatra endpoint: #!/bin/bash /bin/gzip -c /tmp/test.yaml > /tmp/test.gz curl -i <hostname>:<port>/last_run_report -H "Content-Type: application/xml" -H "Content-Encoding: gzip" --data-binary @/tmp/test.gz My sample Ruby app is: require 'sinatra' require 'zlib' require 'stringio' set :port, <port> set :bind, "<ip>" post '/last_run_report' do sio = StringIO.new(request.body.to_s) gz = Zlib::GzipReader.new(sio)

How to fix a “value too long for type character varying(255)” error

最后都变了- 提交于 2021-01-28 09:11:36
问题 I'm trying to save a file so that I can upload it to stripe using CarrierWave, but I'm getting the error: ERROR: value too long for type character varying(255) and don't understand why as I followed the CarrierWave usage guide on GitHub. This is my application: class SplitterStripeServer < Sinatra::Base CarrierWave.configure do |config| config.root = File.dirname(__FILE__) + "/public" end post "/" do img = Image.new img.file = params[:file] #carrierwave will upload the file automatically img

How to filter sensitive information when logging with Sinatra and Rack Logger

落花浮王杯 提交于 2020-07-30 05:53:22
问题 I maintain a Sinatra app that acts as a JSON API service. The API is consumed by another web app, as well as a mobile app. I'd like to have Rack::CommonLogger exclude sensitive information, like a password, from its logs. Rails has this setting enabled, but I have found no documentation how to do this in Sinatra. 回答1: You can try to intercept the call to write and filter out sensitive messages like so : logger = Logger.new("my_common.log") logger.instance_eval do def write(msg) self.send(:<<,