<commit_before>require 'rubygems'
require 'bundler/setup'

require 'sinatra'
require 'dm-core'
require 'dm-postgres-adapter'
require 'dm-migrations'

DataMapper.setup(:default, ENV['DATABASE_URL'])

require 'lib/link'

DataMapper.finalize
DataMapper.auto_upgrade!

get '/' do  
  redirect 'http://kyleslattery.com'
end

get '/links/new/?' do
  if params[:url]
    # just build it, don't show form
    @link = Link.first_or_create(:url => params[:url])
    'http://' + request.env['HTTP_HOST'] + '/' + @link.slug
  else
    erb :new
  end
end

post '/links/?' do
  @link = Link.first_or_create(:url => params[:link][:url])
  @link.slug
end

get '/links/?' do
  @links = Link.all
  erb :list
end

get '/:slug/?' do
  if @link = Link.get_by_slug(params[:slug])
    response['Cache-Control'] = 'public, max-age=300'
    redirect @link.url, 301
  else
    "404!"
  end
end<commit_msg>Properly send 404 status when link isn't found<commit_after>require 'rubygems'
require 'bundler/setup'

require 'sinatra'
require 'dm-core'
require 'dm-postgres-adapter'
require 'dm-migrations'

DataMapper.setup(:default, ENV['DATABASE_URL'])

require 'lib/link'

DataMapper.finalize
DataMapper.auto_upgrade!

get '/' do  
  redirect 'http://kyleslattery.com'
end

get '/links/new/?' do
  if params[:url]
    # just build it, don't show form
    @link = Link.first_or_create(:url => params[:url])
    'http://' + request.env['HTTP_HOST'] + '/' + @link.slug
  else
    erb :new
  end
end

post '/links/?' do
  @link = Link.first_or_create(:url => params[:link][:url])
  @link.slug
end

get '/links/?' do
  @links = Link.all
  erb :list
end

get '/:slug/?' do
  if @link = Link.get_by_slug(params[:slug])
    response['Cache-Control'] = 'public, max-age=300'
    redirect @link.url, 301
  else
    status 404
    "404!"
  end
end
{'fraction_non_alphanumeric': 0.16334440753045404, 'fraction_numerical': 0.013289036544850499, 'mean_word_length': 3.7057291666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6906466', 'n_tokens_mistral': 700, 'n_tokens_neox': 686, 'n_words': 162}