-
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 #59 from pentandra/feature/dynamic-aspects
Feature: dynamic aspects preparation
- Loading branch information
Showing
352 changed files
with
1,466 additions
and
297 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,6 @@ output.diff | |
crash.log | ||
*.autosave | ||
*.bak | ||
items/assets/components/ | ||
items/static/assets/components/ | ||
tmp/ | ||
.bundle |
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,6 +1,6 @@ | ||
[submodule "specifications"] | ||
path = specifications | ||
url = [email protected]:pentandra/specifications.git | ||
[submodule "items/company/benefit-reports"] | ||
path = items/company/benefit-reports | ||
[submodule "benefit-reports"] | ||
path = items/static/company/benefit-reports | ||
url = [email protected]:pentandra/benefit-reports.git |
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
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
usage 'server [options]' | ||
summary 'start the dynamic web server (nginx/OpenResty)' | ||
description <<-EOS | ||
Start the dynamic web server. Running this web server requires OpenResty | ||
to be installed and in scope. | ||
EOS | ||
|
||
required :c, :conf, 'specify the configuration file to use (default: nginx.conf)' | ||
required :g, :global, 'specify any global directives (default: daemon off;)' | ||
|
||
module LifePreserver | ||
class Server < ::Nanoc::CLI::CommandRunner | ||
NGINX_BIN = 'nginx' | ||
NGINX_SEARCH_PATHS = [ | ||
'/usr/local/openresty/nginx/sbin/', | ||
'/usr/local/opt/openresty/bin/', | ||
'/usr/local/bin/', | ||
'/usr/sbin/', | ||
'/opt/openresty/nginx/sbin/' | ||
] | ||
|
||
class Error < ::Nanoc::Int::Errors::Generic | ||
def initialize(command, exit_code) | ||
@command = command | ||
@exit_code = exit_code | ||
end | ||
|
||
def message | ||
"command exited with a nonzero status code #{@exit_code} (command: #{@command.join(' ')})" | ||
end | ||
end | ||
|
||
def run | ||
require 'open3' | ||
|
||
load_site | ||
|
||
conf = options[:conf] || 'nginx.conf' | ||
directives = options[:global] || 'daemon off;' | ||
|
||
|
||
nginx = find_nginx | ||
output_dir = site.config[:output_dir] | ||
cmd = [ nginx, '-p', output_dir, '-c', conf, '-g', directives ] | ||
|
||
Open3.popen3(*cmd) do |_stdin, stdout, stderr, wait_thr| | ||
puts "Starting OpenResty (#{nginx}) in path (#{output_dir}) with config (#{conf}) and global directives (#{directives})" | ||
|
||
stdout_thread = Thread.new do | ||
while (line = stdout.gets) | ||
puts line | ||
end | ||
end | ||
|
||
stderr_thread = Thread.new do | ||
while (line = stderr.gets) | ||
puts line | ||
end | ||
end | ||
|
||
stdout_thread.join | ||
stderr_thread.join | ||
|
||
exit_status = wait_thr.value | ||
unless exit_status.success? | ||
raise Error.new(cmd, exit_status.to_i) | ||
end | ||
end | ||
end | ||
|
||
protected | ||
|
||
def find_nginx | ||
NGINX_SEARCH_PATHS.each do |path| | ||
to_check = path + NGINX_BIN | ||
if File.file?(to_check) && openresty?(to_check) | ||
return to_check | ||
end | ||
end | ||
|
||
# As a last resort, check the PATH | ||
require 'mkmf' | ||
to_check = find_executable0(NGINX_BIN) | ||
if to_check && openresty?(to_check) | ||
return to_check | ||
end | ||
|
||
raise "Cannot find the OpenResty executable in any of the following places: #{NGINX_SEARCH_PATHS.join(':')} or in the current path: #{ENV['PATH']}" | ||
end | ||
|
||
def openresty?(path_to_check) | ||
output, _status = Open3.capture2e(path_to_check, '-v') | ||
output && output['openresty'] | ||
end | ||
end | ||
end | ||
|
||
runner LifePreserver::Server |
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,91 @@ | ||
usage 'view [options]' | ||
summary 'start the web server that serves static files' | ||
description <<-EOS | ||
Start the static web server. Unless specified, the web server will run on port | ||
3000 and listen on all IP addresses. Running this static web server requires | ||
`adsf` (not `asdf`!). | ||
EOS | ||
|
||
required :H, :handler, 'specify the handler to use (webrick/mongrel/...)' | ||
required :o, :host, 'specify the host to listen on (default: 0.0.0.0)' | ||
required :p, :port, 'specify the port to listen on (default: 3000)' | ||
|
||
module Nanoc::CLI::Commands | ||
class View < ::Nanoc::CLI::CommandRunner | ||
DEFAULT_HANDLER_NAME ||= :thin | ||
|
||
def run | ||
load_adsf | ||
require 'rack' | ||
|
||
load_site | ||
|
||
# Set options | ||
options_for_rack = { | ||
Port: (options[:port] || 3000).to_i, | ||
Host: (options[:host] || '0.0.0.0'), | ||
} | ||
|
||
# Get handler | ||
if options.key?(:handler) | ||
handler = Rack::Handler.get(options[:handler]) | ||
else | ||
begin | ||
handler = Rack::Handler.get(DEFAULT_HANDLER_NAME) | ||
rescue LoadError | ||
handler = Rack::Handler::WEBrick | ||
end | ||
end | ||
|
||
# Build app | ||
site = self.site | ||
site_root = site.config[:output_dir] + view_config_root | ||
|
||
app = Rack::Builder.new do | ||
use Rack::CommonLogger | ||
use Rack::ShowExceptions | ||
use Rack::Lint | ||
use Rack::Head | ||
use Adsf::Rack::IndexFileFinder, root: site_root | ||
run Rack::File.new(site_root) | ||
end.to_app | ||
|
||
# Run autocompiler | ||
handler.run(app, options_for_rack) | ||
end | ||
|
||
protected | ||
|
||
def view_config | ||
site.config[:view] || {} | ||
end | ||
|
||
def view_config_root | ||
view_config[:static_root] | ||
end | ||
|
||
def load_adsf | ||
# Load adsf | ||
begin | ||
require 'adsf' | ||
return | ||
rescue LoadError | ||
$stderr.puts "Could not find the required 'adsf' gem, " \ | ||
'which is necessary for the view command.' | ||
end | ||
|
||
# Check asdf | ||
begin | ||
require 'asdf' | ||
$stderr.puts "You appear to have 'asdf' installed, " \ | ||
"but not 'adsf'. Please install 'adsf' (check the spelling)!" | ||
rescue LoadError | ||
end | ||
|
||
# Done | ||
exit 1 | ||
end | ||
end | ||
end | ||
|
||
runner Nanoc::CLI::Commands::View |
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,21 @@ | ||
# This tells Nginx to cache open file handles, "not found" errors, metadata about files and their permissions, etc. | ||
# | ||
# The upside of this is that Nginx can immediately begin sending data when a popular file is requested, | ||
# and will also know to immediately send a 404 if a file is missing on disk, and so on. | ||
# | ||
# However, it also means that the server won't react immediately to changes on disk, which may be undesirable. | ||
# | ||
# In the below configuration, inactive files are released from the cache after 20 seconds, whereas | ||
# active (recently requested) files are re-validated every 30 seconds. | ||
# | ||
# Descriptors will not be cached unless they are used at least 2 times within 20 seconds (the inactive time). | ||
# | ||
# A maximum of the 1000 most recently used file descriptors can be cached at any time. | ||
# | ||
# Production servers with stable file collections will definitely want to enable the cache. | ||
open_file_cache max=1000 inactive=20s; | ||
open_file_cache_valid 30s; | ||
open_file_cache_min_uses 2; | ||
open_file_cache_errors on; | ||
|
||
# vi: ft=nginx |
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,16 @@ | ||
# Cross domain AJAX requests | ||
|
||
# http://www.w3.org/TR/cors/#access-control-allow-origin-response-header | ||
|
||
# **Security Warning** | ||
# Do not use this without understanding the consequences. | ||
# This will permit access from any other website. | ||
# | ||
add_header "Access-Control-Allow-Origin" "*"; | ||
|
||
# Instead of using this file, consider using a specific rule such as: | ||
# | ||
# Allow access based on [sub]domain: | ||
# add_header "Access-Control-Allow-Origin" "subdomain.example.com"; | ||
|
||
# vi: ft=nginx |
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,19 @@ | ||
# The X-Frame-Options header indicates whether a browser should be allowed | ||
# to render a page within a frame or iframe. | ||
add_header X-Frame-Options SAMEORIGIN; | ||
|
||
# MIME type sniffing security protection | ||
# There are very few edge cases where you wouldn't want this enabled. | ||
add_header X-Content-Type-Options nosniff; | ||
|
||
# The X-XSS-Protection header is used by Internet Explorer version 8+ | ||
# The header instructs IE to enable its inbuilt anti-cross-site scripting filter. | ||
add_header X-XSS-Protection "1; mode=block"; | ||
|
||
# with Content Security Policy (CSP) enabled (and a browser that supports it (http://caniuse.com/#feat=contentsecuritypolicy), | ||
# you can tell the browser that it can only download content from the domains you explicitly allow | ||
# CSP can be quite difficult to configure, and cause real issues if you get it wrong | ||
# There is website that helps you generate a policy here http://cspisawesome.com/ | ||
# add_header Content-Security-Policy "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' https://www.google-analytics.com;"; | ||
|
||
# vi: ft=nginx |
Oops, something went wrong.