This repository has been archived by the owner on Oct 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from eonu/master
Remove IP whitelisting + rework static file serving
- Loading branch information
Showing
24 changed files
with
87 additions
and
538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,49 @@ | ||
require 'sinatra' | ||
class ApplicationController < Sinatra::Base | ||
def static(uri, *args) | ||
if env['HTTP_VERSION'] == 'HTTP/1.1' and env["REQUEST_METHOD"] != 'GET' | ||
status 303 | ||
else | ||
status 302 | ||
module Eucalypt | ||
class Static::Router | ||
attr_reader :routes | ||
|
||
def initialize(public_folder) | ||
@routes = [] | ||
@public_folder = public_folder | ||
end | ||
|
||
# According to RFC 2616 section 14.30, "the field value consists of a | ||
# single absolute URI" | ||
response['Location'] = uri(uri.to_s, settings.absolute_redirects?, settings.prefixed_redirects?) | ||
halt(*args) | ||
def route(file, aliases: []) | ||
raise ArgumentError.new("Invalid argument #{file} for 'file' - Expected string (file path with preceding /)") unless file.is_a?(String) && file.start_with?('/') | ||
location = File.join @public_folder, file.sub('/', '') | ||
raise ArgumentError.new("Invalid argument #{file} for 'file' - File \"#{location}\" doesn't exist") unless File.file? location | ||
raise ArgumentError.new("Invalid keyword argument #{aliases} for 'aliases' - Expected Array of String") unless aliases.is_a?(Array) && aliases.all?{|a| a.is_a? String} | ||
raise ArgumentError.new("Invalid keyword argument #{aliases} for 'aliases' - Expected Array of route names (preceded by /)") unless aliases.all?{|a| a.start_with? '/'} | ||
@routes << {file: file, aliases: aliases} | ||
end | ||
|
||
alias_method :<<, :route | ||
end | ||
end | ||
|
||
class ApplicationController < Sinatra::Base | ||
set :static_router, ->{ Eucalypt::Static::Router.new settings.public_folder } | ||
|
||
def self.static(file = nil, aliases: []) | ||
if settings.static_router.is_a? Eucalypt::Static::Router | ||
if block_given? | ||
yield settings.static_router | ||
settings.static_router.routes.each do |route| | ||
route.values.flatten.each do |path| | ||
get(path) { send_file File.join(settings.public_folder, route[:file].sub('/','')) } | ||
end | ||
end | ||
else | ||
if file && aliases | ||
raise ArgumentError.new("Invalid argument #{file} for 'file' - Expected string (file path with preceding /)") unless file.is_a?(String) && file.start_with?('/') | ||
location = File.join settings.public_folder, file.sub('/', '') | ||
raise ArgumentError.new("Invalid argument #{file} for 'file' - File \"#{location}\" doesn't exist") unless File.file? location | ||
raise ArgumentError.new("Invalid keyword argument #{aliases} for 'aliases' - Expected Array of String") unless aliases.is_a?(Array) && aliases.all?{|a| a.is_a? String} | ||
raise ArgumentError.new("Invalid keyword argument #{aliases} for 'aliases' - Expected Array of route names (preceded by /)") unless aliases.all?{|a| a.start_with? '/'} | ||
routes = [file] + aliases | ||
routes.each {|path| get(path){send_file location} } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
lib/eucalypt/core/templates/eucalypt/app/controllers/application_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class ApplicationController < Sinatra::Base | ||
helpers do | ||
def guard | ||
settings.guard | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Eucalypt | ||
VERSION = '0.5.1' | ||
VERSION = '0.5.2' | ||
end |
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.