Adds tests, travis support and more
This commit is contained in:
parent
ab78b5e144
commit
e44902899c
|
@ -0,0 +1,4 @@
|
|||
language: ruby
|
||||
rvm:
|
||||
- 2.2.2
|
||||
script: ruby test.rb
|
7
Gemfile
7
Gemfile
|
@ -2,4 +2,11 @@ source "https://rubygems.org"
|
|||
ruby '2.2.2'
|
||||
|
||||
gem 'sinatra'
|
||||
|
||||
group :test do
|
||||
gem 'minitest'
|
||||
end
|
||||
|
||||
group :production do
|
||||
gem 'thin'
|
||||
end
|
|
@ -1,6 +1,8 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
daemons (1.2.3)
|
||||
eventmachine (1.0.8)
|
||||
minitest (5.7.0)
|
||||
rack (1.6.4)
|
||||
rack-protection (1.5.3)
|
||||
|
@ -9,6 +11,10 @@ GEM
|
|||
rack (~> 1.4)
|
||||
rack-protection (~> 1.4)
|
||||
tilt (>= 1.3, < 3)
|
||||
thin (1.6.3)
|
||||
daemons (~> 1.0, >= 1.0.9)
|
||||
eventmachine (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
tilt (2.0.1)
|
||||
|
||||
PLATFORMS
|
||||
|
@ -17,6 +23,7 @@ PLATFORMS
|
|||
DEPENDENCIES
|
||||
minitest
|
||||
sinatra
|
||||
thin
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.5
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# lightsaber
|
||||
# lightsaber [![Build Status](https://travis-ci.org/captn3m0/lightsaber.svg)](https://travis-ci.org/captn3m0/lightsaber)
|
||||
|
||||
Lightsaber is a simple DNS Redirect service. It offers 301/302 redirects for
|
||||
your domains. The configuration is kept public on this github repository itself.
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
require 'rubygems'
|
||||
require 'bundler/setup'
|
||||
require 'sinatra'
|
||||
require 'yaml'
|
||||
|
||||
get '/' do
|
||||
hostname = request.host
|
||||
YAML::load_file('redirects.yml').each do |code, zone|
|
||||
if zone.has_key? hostname
|
||||
redirect zone[hostname], code
|
||||
end
|
||||
end
|
||||
|
||||
halt 404, "#{hostname} hasn't been setup yet."
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
require File.expand_path '../app.rb', __FILE__
|
||||
|
||||
run Sinatra::Application
|
18
config.yml
18
config.yml
|
@ -1,4 +1,14 @@
|
|||
301:
|
||||
github.captnemo.in: https://github.com/captn3m0
|
||||
302:
|
||||
fb.captnemo.in: https://facebook.com/captn3m0
|
||||
---
|
||||
environment: production
|
||||
chdir: /home/lightsaber/lightsaber
|
||||
address: 127.0.0.1
|
||||
user: lightsaber
|
||||
group: lightsaber
|
||||
port: 4567
|
||||
pid: /tmp/lightsaber.pid
|
||||
rackup: /home/lightsaber/lightsaber/config.ru
|
||||
log: /home/lightsaber/lightsaber/thin.log
|
||||
max_conns: 1024
|
||||
timeout: 5
|
||||
max_persistent_conns: 256
|
||||
daemonize: true
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
301:
|
||||
github.captnemo.in: https://github.com/captn3m0
|
||||
lightsaber.captnemo.in: https://github.com/captn3m0/lightsaber
|
||||
302:
|
||||
fb.captnemo.in: https://facebook.com/captn3m0
|
10
test.rb
10
test.rb
|
@ -4,14 +4,14 @@ require 'yaml'
|
|||
require 'pp'
|
||||
|
||||
class TestConfig < Minitest::Test
|
||||
REDIRECTS = ['301', '302']
|
||||
REDIRECTS = [301, 302]
|
||||
def setup
|
||||
@config = YAML::load_file 'config.yml'
|
||||
@config = YAML::load_file 'redirects.yml'
|
||||
end
|
||||
|
||||
def test_redirect_sections
|
||||
@config.each do |section, zone|
|
||||
assert REDIRECTS.include? section.to_s
|
||||
@config.each do |code, zone|
|
||||
assert REDIRECTS.include? code
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -25,7 +25,7 @@ class TestConfig < Minitest::Test
|
|||
end
|
||||
|
||||
def resolves_to_lightsaber(domain)
|
||||
flag = false
|
||||
flag = domain === "lightsaber.captnemo.in"
|
||||
Resolv::DNS.open do |dns|
|
||||
records = dns.getresources domain, Resolv::DNS::Resource::IN::CNAME
|
||||
records.each do |record|
|
||||
|
|
Loading…
Reference in New Issue