sinatra

Robust way to deploy a Rack application (Sinatra)

孤人 提交于 2019-12-04 12:19:52
问题 I'm looking for a robust way to deploy a Rack application (in this case a Sinatra app). Requests will take a little time (0.25-0.5 sec waiting on proxied HTTP requests) and there may be a decent amount of traffic. Should I go with a traditional mongrel cluster setup? Use HAProxy as a load balancer? nginx? rackup? What solutions have you used and what are the advantages? 回答1: Nginx / Unicorn FTW! Nginx in front to serve static files and unicorn to handle Sinatra app. Benefits: Performance,

Is there a way to flush html to the wire in Sinatra

帅比萌擦擦* 提交于 2019-12-04 12:17:28
问题 I have a Sinatra app with a long running process (a web scraper). I'd like the app flush the results of the crawler's progress as the crawler is running instead of at the end. I've considered forking the request and doing something fancy with ajax but this is a really basic one-pager app that really just needs to output a log to a browser as it's happening. Any suggestions? 回答1: Update (2012-03-21) As of Sinatra 1.3.0, you can use the new streaming API: get '/' do stream do |out| out << "foo

Simple Search With Datamapper and Sinatra

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 11:47:59
I'm fairly new to Ruby and backend development in general. That being said I'm trying to create a simple search form. I'm using Sinatra as the framework and Datamapper as my ORM. What is the best way to do this? Below is my schema I would like the search action to search both the tile and category. require 'sinatra' require 'datamapper' DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/cal.db") class Event include DataMapper::Resource property :id, Serial property :title, String property :text, Text property :contact_name, String property :contact_email, String property :location, String

Accessing headers from Sinatra

青春壹個敷衍的年華 提交于 2019-12-04 10:36:16
问题 I am trying to access the headers in a filter in sinatra. My request includes the header "HTTP_AUTH", however I can't access it. My filter is before do halt 403 unless request['HTTP_AUTH'] == 'test' end It works correctly from my rack test. browser.get '/mypath', "CONTENT_TYPE" => "application/json", "HTTP_AUTH" => 'test' But when I try from other sources I can't access it. If I puts request.env I can see the token is in the request, but I can't access it. "HTTP_CONNECTION"=>"close", "HTTP

How do I log asynchronous thin+sinatra+rack requests?

天大地大妈咪最大 提交于 2019-12-04 10:20:11
I'm writing my first Sinatra-based web app as a frontend to another TCP-based service, using EventMachine and async_sinatra to process incoming HTTP requests asynchronously. When I'm testing my app, all requests to synchronous routes are logged to stdout in common log format, but asynchronous requests are not. I've read through bits of the source code to async_sinatra, Sinatra, Thin, and Rack, and it looks like logging of synchronous requests is done through CommonLogger#call. However, I can't find anywhere in the asynchronous code in async_sinatra or Thin that seems to pass asynchronous

What do you use Sinatra for? [closed]

丶灬走出姿态 提交于 2019-12-04 09:55:54
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Im confused about Sinatra (the ruby framework). Is it a lightweight Rails replacement or you can have them running side by side? Can

Sinatra, JavaScript Cross-Domain Requests JSON

限于喜欢 提交于 2019-12-04 08:46:31
问题 I run a REST-API build on top of Sinatra. Now I want to write a jQuery Script that fetches data from the API. Sinatra is told to response with JSON before do content_type :json end A simple Route looks like get '/posts' do Post.find.to_json end My jQuery script is a simple ajax-call $.ajax({ type: 'get', url: 'http://api.com/posts', dataType: 'json', success: function(data) { // do something } }) Actually everything works fine as long as both runs on the same IP, API and requesting JS. I

Prepared Statement doesn't exist

妖精的绣舞 提交于 2019-12-04 08:35:02
Currently running a simple sinatra app, using passenger, and using pgbouncer for connection pooling to a database on the same server as the app. Currently I am intermittently getting a PG error that the prepared statement "a\d" doesn't exist. A PG::Error occurred in #: ERROR: prepared statement "a2" does not exist the ruby code that is executed before the error def self.get_ownership_record(id, key) self.where("user_id=? AND key=?", id, key ).first end pgbouncer config ; ######################################################### ; ############# SECTION HEADER [DATABASES] ################ ; ####

Suitability of Rails, Padrino, and Sinatra for building a prepaid mobile service

旧街凉风 提交于 2019-12-04 07:46:18
问题 I am working on an application in the Mobile/VOIP domain. This is really a gray area for me. Here are some details about the application: This is basically like an auto recharge / prepaid mobile service Will have logic of medium complexity compared to previous ERP apps I've written. The Views sections in the response will be plain text, which will be sent as SMS/USSD pull to user and Voice XML (VXML) that will be sent as an IVR Response to users. The routing logic is very simple, as only two

Rack Sessions getting lost in Chrome

╄→гoц情女王★ 提交于 2019-12-04 07:26:09
I have an pretty simple app hosted on EC2 built with Sinatra, served with thin behind nginx. The problem is that with Chrome, the session variables get 'lost' in Sinatra. It does not happen in Firefox. This is using Rack::Session::Cookie. This is similar to this issue: Sinatra not persisting session with redirect on Chrome Any insights in how to solve this issues in Chrome would be appreciated. Make sure you are setting the following: configure :development do set(:session_secret, 'a random string that wont change') end configure :production do set(:session_secret, '*&(${)UIJH$(&*(&*(@(*)(!))