Skip to content

Instantly share code, notes, and snippets.

@rjurney
Created August 23, 2014 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjurney/87c8dcbee588078102f6 to your computer and use it in GitHub Desktop.
Save rjurney/87c8dcbee588078102f6 to your computer and use it in GitHub Desktop.
Why are my controllers responding with 404?
Sinatra doesn’t know this ditty.
Try this:
get '/network' do
"Hello World"
end
[2014-08-23 12:38:41] INFO WEBrick 1.3.1
[2014-08-23 12:38:41] INFO ruby 1.9.3 (2013-05-16) [java]
== Sinatra/1.4.5 has taken the stage on 4567 for development with backup from WEBrick
[2014-08-23 12:38:41] INFO WEBrick::HTTPServer#start: pid=5564 port=4567
0:0:0:0:0:0:0:1 - - [23/Aug/2014 12:38:44] "GET / HTTP/1.1" 404 437 0.0220
0:0:0:0:0:0:0:1 - - [23/Aug/2014:12:38:44 PDT] "GET / HTTP/1.1" 404 437
- -> /
0:0:0:0:0:0:0:1 - - [23/Aug/2014 12:38:44] "GET /__sinatra__/404.png HTTP/1.1" 304 - 0.0100
[2014-08-23 12:38:44] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
0:0:0:0:0:0:0:1 - - [23/Aug/2014:12:38:44 PDT] "GET /__sinatra__/404.png HTTP/1.1" 304 0
http://localhost:4567/ -> /__sinatra__/404.png
0:0:0:0:0:0:0:1 - - [23/Aug/2014 12:38:49] "GET /network HTTP/1.1" 404 444 0.0070
0:0:0:0:0:0:0:1 - - [23/Aug/2014:12:38:49 PDT] "GET /network HTTP/1.1" 404 444
- -> /network
0:0:0:0:0:0:0:1 - - [23/Aug/2014 12:38:49] "GET /__sinatra__/404.png HTTP/1.1" 304 - 0.0120
[2014-08-23 12:38:49] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
0:0:0:0:0:0:0:1 - - [23/Aug/2014:12:38:49 PDT] "GET /__sinatra__/404.png HTTP/1.1" 304 0
http://localhost:4567/network -> /__sinatra__/404.png
^C== Sinatra has ended his set (crowd applauds)
#!/Users/rjurney/.rvm/rubies/jruby-1.7.4/bin/jruby
require 'rubygems'
require 'sinatra'
require 'sinatra/reloader'
require 'json'
require_relative 'lib/json_serializable_graph.rb'
def usage
puts "Usage: bundle exec ./index.rb <filename.gdf>"
end
# Initialize with a gdf file containing X/Y coordinates
def parse_gdf(gdf_path)
g = JSONSerializableGraph::load(gdf_path)
end
# Load the graph
if not ARGV[0]
usage
exit
end
g = parse_gdf(ARGV[0])
get '/' do
puts "GOT /"
erb :'index.html'
end
get '/network' do
puts "GOT /network"
puts g.to_json
g.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment