rack

Use Rack::CommonLogger in Sinatra

半城伤御伤魂 提交于 2019-11-27 11:03:13
I have a small web-server that I wrote with Sinatra. I want to be able to log messages to a log file. I've read through http://www.sinatrarb.com/api/index.html and www.sinatrarb.com/intro.html, and I see that Rack has something called Rack::CommonLogger, but I can't find any examples of how it can be accessed and used to log messages. My app is simple so I wrote it as a top-level DSL, but I can switch to subclassing it from SinatraBase if that's part of what's required. Roman Gonzalez Rack::CommonLogger won't provide a logger to your main app, it will just logs the request like Apache would do

Logging in Sinatra?

让人想犯罪 __ 提交于 2019-11-27 11:01:22
I'm having trouble figuring out how to log messages with Sinatra. I'm not looking to log requests, but rather custom messages at certain points in my app. For example, when fetching a URL I would like to log "Fetching #{url}" . Here's what I'd like: The ability to specify log levels (ex: logger.info("Fetching #{url}") ) In development and testing environments, the messages would be written to the console. In production, only write out messages matching the current log level. I'm guessing this can easily be done in config.ru , but I'm not 100% sure which setting I want to enable, and if I have

How to redirect without www using Rails 3 / Rack?

我只是一个虾纸丫 提交于 2019-11-27 09:41:05
问题 I understand there are a lot of questions that answer this. I'm familiar with .htaccess and nginx.conf methods, but I do not have access to such traditional configuration methods on heroku. Simone Carletti gave this answer that leverages Rails 2.x Metals, but I'm using Rails 3 and this isn't compatible. Redirect non-www requests to www urls in Rails Please note: I'm not looking for a simple before_filter in my ApplicationController. I'd like to accomplish a rewrite similar to Simone's. I

Any success with Sinatra working together with EventMachine WebSockets?

大城市里の小女人 提交于 2019-11-27 05:01:05
问题 I have been using Sinatra for sometime now and I would like to add some realtime features to my web-app by pushing the data via websockets. I have successfully used the gem 'em-websocket' on its own, but have not been able to write one ruby file that has a sinatra web server AND a web-socket server. I've tried spinning the run! or start! methods off in separate threads with no success. Has anyone gotten this to work? I want to have them in the same file as I can then share variables between

Testing Rack Routing Using rSpec

两盒软妹~` 提交于 2019-11-27 03:49:27
问题 I have a rule in my routes.rb: constraints AssetRestrictor do match '*seopath' => SeoDispatcher end Then in lib/seo_dispatcher.rb, I have this: class SeoDispatcher AD_KEY = "action_dispatch.request.path_parameters" def self.call(env) seopath = env[AD_KEY][:seopath] if seopath params = seopath.split('/') # get array of path components env[AD_KEY][:id] = params.last # the real page name is the last element env[AD_KEY][:category] = params.first if params.length > 1 end Rails.logger.debug

git, Heroku: pre-receive hook declined

寵の児 提交于 2019-11-26 20:55:33
问题 I am in the process of setting up a git repository and attempting to link it to Heroku. When I run the command git push heroku master I receive Counting objects: 7, done. Delta compression using up to 2 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (7/7), 714 bytes, done. Total 7 (delta 1), reused 0 (delta 0) -----> Heroku receiving push ! Heroku push rejected due to an unrecognized error. ! We've been notified, see http://support.heroku.com if the problem persists. To

Bypassing rack version error using Rails 2.3.5

孤者浪人 提交于 2019-11-26 20:44:13
问题 I'm currently on Dreamhost attempting to run a Rails 2.3.5 app. Here is the situation, Dreamhost's servers have Rails 2.2.2 installed. Of course, I can't update a shared host's rails version, so I froze my Rails in vendor. Rails 2.3.5 requires the rack v1.0.1 gem. Dreamhost uses the rack v1.0.0 gem. So when I try to define: config.gem "rack", :version => "1.0.1" I get: can't activate rack (~> 1.0.1, runtime) for [], already activated rack-1.0.0 for [] So what I really need to do is bypass my

How do you configure WEBrick to use SSL in Rails?

穿精又带淫゛_ 提交于 2019-11-26 20:08:22
Prior to Rails 3, you could modify the script/server file to add in SSL parameters and tell the server command to use the HTTPS version of WEBrick. Now that all of those scripts are gone, does anyone know how to get this to work with Rails 3 or 4? JustinParker While the scripts directory in Rails 4 is gone, the bin directory remains. You can get WEBrick working with an SSL certificate by editing the bin/rails script. Tested on Rails 4 and Ruby 2.1.1, installed with rbenv. Much of this is from this blog post and this Stack Overflow question . #!/usr/bin/env ruby require 'rails/commands/server'

What is Rack middleware?

蹲街弑〆低调 提交于 2019-11-26 19:10:59
What is Rack middleware in Ruby? I couldn't find any good explanation for what they mean by "middleware". Chris McCauley Rack as Design Rack middleware is more than "a way to filter a request and response" - it's an implementation of the pipeline design pattern for web servers using Rack . It very cleanly separates out the different stages of processing a request - separation of concerns being a key goal of all well designed software products. For example with Rack I can have separate stages of the pipeline doing: Authentication : when the request arrives, are the users logon details correct?

How to serve static files via Rack?

这一生的挚爱 提交于 2019-11-26 18:59:35
问题 I am currently developing a Rack-based application and want to redirect all file requests(e.g. filename.filetype) to a specified folder. Rack::Static only supports file requests for a special folder(e.g. "/media"). Do I have to write an own Rack middleware or does a out-of-the-box solution exist? Best regards 回答1: To redirect every request to a particular path, use Rack::File (for some reason this class is absent in recent documentation, but it is still part of the latest Rack): run Rack: