I am working with an app and am looking to deploy to heroku. Full source here.
The primary error that I am seeing is
heroku[router]: at=info method=GET path="/" host=cheesyparts.herokuapp.com request_id=25d2dbb5-e13a-4146-bb3a-9386f997c44c fwd="54.234.191.55" dyno=web.1 connect=2 service=3 status=404 bytes=417
Locally when I attempt to lauch via foreman the same issue occurs. However, I am able to launch the server and run it if I use the ruby parts_server_control.rb run. Any tip is appreciated.
The config.ru looks like this
require './parts_server'
run Sinatra::Application
and the control script parts_server_control.rb looks like:
require "bundler/setup"
require "daemons"
require "pathological"
require "thin"
Daemons.run_proc("parts_server", :monitor => true) do
require "parts_server"
Thin::Server.start("0.0.0.0", PORT, CheesyParts::Server)
end
The control script is running the app class CheesyParts::Server, but your but your config.ru (used by foreman and Heroku) assumes the app written in the classic style and is using the class Sinatra::Application. See the Sinatra docs on modular and classic application styles. Since nothing is added to Sinatra::Application it is an “empty” app and so you will get 404 errors for any route.
The fix is to change the line
run Sinatra::Application
in your config.ru to
run CheesyParts::Server
so that that class will be used as the main app.
Related
I am facing asset loading issue in Rails 5 application deployed on Heroku.
App Configuration is,
ruby => ‘2.3.1’
rails => '~> 5.0.1'
When image is stored on path,
app/assets/home/image1.jpg
I am accessing it in view as,
= image_tag('/assets/home/image1.jpg’)
which is working properly in Development ENV, but not in Production ENV.
As per Heroku log,
ActionController::RoutingError (No route matches [GET]
"/assets/home/image1.jpg")
If I am moving image directly to
app/assets/image1.jpg
then its working on Production ENV.
Please guide about it.
Thanks
It looks like you assets are not compile on heroku.
Follow below code:
config/environments/production.rb
config.assets.compile = true
then run commands:
RAILS_ENV=production rake assets:precompile
then push all compiled files with menifest file to heroku.
I'm going through a recently released book on Sinatra that demonstrates this way of setting up routes in different files:
# app.rb
require "sinatra"
require "slim"
class Todo < Sinatra::Base
# ...
Dir[File.join(File.dirname(__FILE__), "lib", "*.rb")].each { |lib| require lib }
end
# lib/routes.rb
get "/test" do
"The application is running"
end
# config.ru
require "sinatra"
require "bundler/setup"
Bundler.require
ENV["RACK_ENV"] = "development"
require File.join(File.dirname(__FILE__), "app.rb")
Todo.start!
However, it fails to find the route at http://localhost:4567/test. It would make sense to me that this should work when I run ruby config.ru or bundle exec rackup -p 4567. But coming from Rails development where all this configuration is built-in, I don't have a complete understanding of how everything gets wired together. The server is running on that port and I get the Sinatra doesn't know this ditty 404 page. If I reopen the class as suggested by this SO answer, the /test route is found.
# lib/routes.rb
class Todo < Sinatra::Base
get "/test" do
"The application is running"
end
end
Is there something I'm missing about this suggested way to include routes without reopening the class?
Try ruby app.rb, it should work.
You'll need to restart the webserver to load routes that were added while it was running. Routes are loaded into memory when app.rb is invoked and Sinatra is launched. The route itself looks fine and it appears routes.rb is being imported successfully via Dir[File.join(File.dirname(__FILE__), "lib", "*.rb")].each { |lib| require lib }.
If you're running the server directly through terminal Ctrl+X, Ctrl+C should shut it down, then restart it via rackup config.ru* or ruby app.rb. You may confirm the route is recognized by making a get request through your browser to: http://127.0.0.1:4567/test.
For the rackup config.ru command to work, you can change config.ru to something like:
# config.ru
require './app'
run Sinatra::Application
This is just a deployment convenience.
Edit: #shaun, because Todo extends Sinatra::Base it's fine to use run Todo in your case.
The book suggested Todo.start! to run the application from the config.ru file, but the Sinatra documentation example uses run Sinatra::Application. So I just changed the line from Todo.start! to
run Todo
That seems to work, but I'll have to look into the consequences.
I added the demo files and ran the app just fine locally
But I ran into problems when i deployed to heroku, the content was not showing
I read through the documentation on the official site for nesta at
http://nestacms.com/docs/deployment/heroku
But they pretty much just make a comment rather than offering instruction
Make sure that you fill in config/config.yml properly (the most important thing is to ensure that caching is off, as we can’t write to Heroku’s file system).
Well I followed their documentation elsewhere
http://nestacms.com/docs/config
And then made changes to my config.yml file. Most relevant changes below
title: "Practice Nesta Site"
subtitle: "Nesta is pretty cool"
author:
name: Juan Gallardo
uri: nestademo1.herokuapp.com
email: jgallardo720#gmail.com
# cache
# Set it to true if you'd like Nesta to cache your pages in ./public.
# Useful if you're deploying Nesta with a proxy server such as Nginx,
# but not in the least bit helpful if your pages are dynamic, or you're
# deploying Nesta to Heroku.
#
cache: false
# content
# The root directory where nesta will look for your article files.
# Should contain "pages" and "attachments" subdirectories that contain
# your actual content and the (optional) menu.txt file that links to your
# main category pages.
#
content: content
# Overriding "cache" and "content" in production is recommended if you're
# deploying Nesta to your own server (but see the deployment documentation
# on the Nesta site). Setting google_analytics_code in production is
# recommended regardless of how you're deploying (if you have a GA account!).
#
# Don't forget to uncomment the "production:" line too...
production:
cache: false
content: /var/apps/nesta/shared/content
# google_analytics_code: "UA-???????-?"
read_more: See full page
Full file at this gist
https://gist.github.com/JGallardo/6195651
I ran heroku logs
jgallardo:demo-site juan.gallardo$ heroku logs
2013-08-09T17:22:21+00:00 heroku[slug-compiler]: Slug compilation started
2013-08-09T17:23:35.001505+00:00 heroku[api]: Scale to web=1 by jgallardo720#gmail.com
2013-08-09T17:23:35.026933+00:00 heroku[api]: Deploy 953af2e by jgallardo720#gmail.com
2013-08-09T17:23:35.046866+00:00 heroku[api]: Release v3 created by jgallardo720#gmail.com
2013-08-09T17:23:35.085708+00:00 heroku[api]: Deploy 953af2e by jgallardo720#gmail.com
2013-08-09T17:23:35+00:00 heroku[slug-compiler]: Slug compilation finished
2013-08-09T17:23:39.139164+00:00 heroku[web.1]: Starting process with commandbundle exec rackup config.ru -p 4751
2013-08-09T17:23:42.686255+00:00 app[web.1]: [2013-08-09 17:23:42] INFO WEBrick 1.3.1
2013-08-09T17:23:42.686255+00:00 app[web.1]: [2013-08-09 17:23:42] INFO ruby 2.0.0 (2013-06-27) [x86_64-linux]
2013-08-09T17:23:42.686477+00:00 app[web.1]: [2013-08-09 17:23:42] INFO WEBrick::HTTPServer#start: pid=2 port=4751
2013-08-09T17:23:43.030091+00:00 heroku[web.1]: State changed from starting to up
2013-08-09T17:36:17.229501+00:00 heroku[router]: at=info method=GET path=/ host=nestademo1.herokuapp.com fwd="98.173.1.66" dyno=web.1 connect=4ms service=51ms status=404 bytes=1570
2013-08-09T17:36:17.658553+00:00 heroku[router]: at=info method=GET path=/css/master.css host=nestademo1.herokuapp.com fwd="98.173.1.66" dyno=web.1 connect=4ms service=129ms status=200 bytes=5548
This line is the problem:
content: /var/apps/nesta/shared/content
Change it to this:
content: content
And make sure that your content is checked into the code repo. You've probably found this page already, right? http://nestacms.com/docs/deployment/heroku
My Sinatra app was working on my local server a few days ago, but now it simply isn't running, and all I get is a blank screen. Even when I deploy to Heroku, nothing works.
Here's a GitHub repository where you can check out my code: https://github.com/aayalur/Sinfoursq
I think the problem is with my config.ru file.
# Gemfile
#require "rubygems"
#require "bundler/setup"
#require "sinatra"
require "./main"
set :run, false
set :raise_errors, true
run Sinatra::Application
Thanks!
You app doesn't display anything because you haven't closed a script tag. You would have noticed that if you inspected the DOM.
By the way, you start your app twice: once in main.rb, and then in config.ru.
You can notice that when Ctrl+C'ing the app: it starts again and you gotta shut it down a second time.
Since your app needs to be run on Rack, get rid of the Sinatra.run! if __FILE__ == $0 and start it with rackup, as explained in Sinatra's documentation.
This will fix the problems related to running the app.
In your config.ru leave this way:
require "rubygems"
require "bundler"
Bundler.require
require "./app"
run Sinatra::Application
I have a really basic Sinatra site working locally. I am using the "rackup" thing, where you define a config.ru like this:
require './web'
use Rack::ShowExceptions
run App.new
And then in the terminal you can run 'rackup' and a web server is fired up and all is well.
However, when I deploy this to heroku I don't get any error messages, but, when I visit the site, it says the standard "Sinatra does not know this ditty" error.
Here is a snippet of my web.rb in case it helps:
require 'sinatra'
require 'maruku'
require 'mustache/sinatra'
require 'nokogiri'
class App < Sinatra::Base
register Mustache::Sinatra
require './views/layout'
set :mustache, {
:views => './views/',
:templates => './templates/'
}
get '/' do
"FUUUUUUUUUUUUU"
end
Edit
Looking at the heroku logs, it appears like sinatra starts and then stops; it doesn't keep running. Then when someone makes a request obviously the server returns a 404
2012-01-20T12:39:23+00:00 app[web.1]: == Sinatra/1.1.0 has taken the stage on 16662 for development with backup from Thin
2012-01-20T12:39:23+00:00 app[web.1]: >> Thin web server (v1.2.7 codename No Hup)
2012-01-20T12:39:23+00:00 app[web.1]: >> Maximum connections set to 1024
2012-01-20T12:39:23+00:00 app[web.1]: >> Listening on 0.0.0.0:16662, CTRL+C to stop
2012-01-20T12:39:23+00:00 app[web.1]: == Sinatra has ended his set (crowd applauds)
2012-01-20T12:39:23+00:00 app[web.1]:
2012-01-20T12:39:23+00:00 app[web.1]: >> Stopping ...
2012-01-20T12:39:23+00:00 heroku[web.1]: Process exited
2012-01-20T12:39:24+00:00 heroku[router]: GET young-river-2245.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=48ms status=404 bytes=409
Whenever you inherit from Sinatra::Base you must require 'sinatra/base' rather than require 'sinatra' at the top of your web.rb file.
I just ran a simple test using your snippets and was able to replicate and then fix the error by doing this.