rackstaticapp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/release.yml +58 -0
- data/.github/workflows/test.yml +18 -0
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +3 -0
- data/Rakefile +15 -0
- data/lib/rackstaticapp/version.rb +3 -0
- data/lib/rackstaticapp.rb +98 -0
- data/rackstaticapp.gemspec +28 -0
- data/spec/public/404.html +1 -0
- data/spec/public/about.html +1 -0
- data/spec/public/css/style.css +1 -0
- data/spec/public/images/image.svg +1 -0
- data/spec/public/index.html +1 -0
- data/spec/spec.rb +64 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b75d295d744a5d99244465bf09f844411d6454aee410078f250b1189fb07859e
|
4
|
+
data.tar.gz: 43a72ce12e72f8de8d009dafce6d28dfa34924ede1ef95cf01282c4d653d7b18
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 723187e70cddd2b1ecf20e60fed9662a09d9c67f765500aa1e9bb50db7b1c3db9bfa9eae277943fef39130b22c27f65a673a38dd070c14768fdc7bb4dd73c037
|
7
|
+
data.tar.gz: b1b5e00ea182da1211d6934fffe5683f627c833983a18f955248ee5c7d771270fc19973e9095047c257eca3332241d86e68e27f81acf51508a4c3aa2a499e366
|
@@ -0,0 +1,58 @@
|
|
1
|
+
name: Release
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- "master" # main only
|
6
|
+
|
7
|
+
permissions:
|
8
|
+
contents: write
|
9
|
+
pull-requests: write
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
release:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
steps:
|
15
|
+
- uses: GoogleCloudPlatform/release-please-action@v2
|
16
|
+
id: release
|
17
|
+
with:
|
18
|
+
release-type: ruby
|
19
|
+
package-name: rackstaticapp
|
20
|
+
bump-minor-pre-major: true
|
21
|
+
bump-patch-for-minor-pre-major: true
|
22
|
+
version-file: "lib/rackstaticapp/version.rb"
|
23
|
+
|
24
|
+
# Checkout code if release was created
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
if: ${{ steps.release.outputs.release_created }}
|
27
|
+
|
28
|
+
# Setup ruby if a release was created
|
29
|
+
- uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
bundler-cache: true
|
32
|
+
if: ${{ steps.release.outputs.release_created }}
|
33
|
+
- name: Run tests
|
34
|
+
run: |
|
35
|
+
bundle exec rake test
|
36
|
+
if: ${{ steps.release.outputs.release_created }}
|
37
|
+
|
38
|
+
# Publish
|
39
|
+
- name: publish gem
|
40
|
+
run: |
|
41
|
+
mkdir -p $HOME/.gem
|
42
|
+
touch $HOME/.gem/credentials
|
43
|
+
chmod 0600 $HOME/.gem/credentials
|
44
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
45
|
+
bundle exec rake build
|
46
|
+
gem push pkg/*.gem
|
47
|
+
env:
|
48
|
+
# Make sure to update the secret name
|
49
|
+
# if yours isn't named RUBYGEMS_AUTH_TOKEN
|
50
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
51
|
+
if: ${{ steps.release.outputs.release_created }}
|
52
|
+
|
53
|
+
- name: Upload Release Artifact
|
54
|
+
if: ${{ steps.release.outputs.release_created }}
|
55
|
+
env:
|
56
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
57
|
+
run:
|
58
|
+
gh release upload ${{ steps.release.outputs.tag_name }} pkg/*.gem
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Run tests
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- "**" # matches every branch
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
run-tests:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- name: Set up Ruby
|
13
|
+
uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
bundler-cache: true
|
16
|
+
- name: Run tests
|
17
|
+
run: |
|
18
|
+
bundle exec rake test
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.1.0 (2023-09-10)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* Integrated PR [#6](https://www.github.com/iphoting/RackStaticApp/issues/6) from upstream Vienna repo. ([5e560b0](https://www.github.com/iphoting/RackStaticApp/commit/5e560b02fddf9c5e3b57b98c1cbd2c2c1db8cfa3))
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'yard'
|
3
|
+
|
4
|
+
task :default => :test
|
5
|
+
|
6
|
+
desc 'Run tests'
|
7
|
+
task :test do
|
8
|
+
Dir.chdir 'spec'
|
9
|
+
system 'ruby -I ../lib spec.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
YARD::Rake::YardocTask.new do |t|
|
13
|
+
t.files = ['lib/**/*.rb']
|
14
|
+
t.options = ['--markup=markdown']
|
15
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'rackstaticapp/version'
|
2
|
+
require 'rack'
|
3
|
+
require 'vienna'
|
4
|
+
|
5
|
+
##
|
6
|
+
# Zero-configuration convenience wrapper around `RackStaticApp::Application`, which inherits from `Vienna::Application`.
|
7
|
+
# Add this to your `config.ru`:
|
8
|
+
#
|
9
|
+
# require 'rackstaticapp'
|
10
|
+
# run RackStaticApp
|
11
|
+
#
|
12
|
+
# Your static site in `public` will be served.
|
13
|
+
#
|
14
|
+
|
15
|
+
module RackStaticApp
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def call(env)
|
19
|
+
Application.new.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# `RackStaticApp::Static` is just a wrapper for `Rack::Static` with
|
25
|
+
# sane and opinionated options.
|
26
|
+
#
|
27
|
+
# It serves all files under the given `root` and doesn't passes on requests
|
28
|
+
# for files that don't exist.
|
29
|
+
#
|
30
|
+
# Examples
|
31
|
+
#
|
32
|
+
# use RackStaticApp::Static, 'public'
|
33
|
+
#
|
34
|
+
|
35
|
+
class Static < Vienna::Static
|
36
|
+
def initialize(app, root)
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
def urls
|
41
|
+
[""]
|
42
|
+
end
|
43
|
+
|
44
|
+
def root
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
def index
|
49
|
+
super
|
50
|
+
end
|
51
|
+
|
52
|
+
def header_rules
|
53
|
+
super
|
54
|
+
end
|
55
|
+
|
56
|
+
def options
|
57
|
+
{urls: urls, root: root, index: index, header_rules: header_rules, cascade: true}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# `RackStaticApp::NotFound` is a default endpoint not unlike `Rack::NotFound`.
|
63
|
+
# Initialize it with the path to a 404 page and its contents will be served.
|
64
|
+
# The difference is that if a 404 page doesn't exist, a default response,
|
65
|
+
# 'Not Found' will be served.
|
66
|
+
#
|
67
|
+
# Examples
|
68
|
+
#
|
69
|
+
# run RackStaticApp::NotFound.new('public/404.html')
|
70
|
+
#
|
71
|
+
# run RackStaticApp::NotFound.new # Always return 'Not Found'
|
72
|
+
#
|
73
|
+
|
74
|
+
class NotFound < Vienna::NotFound
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# `RackStaticApp::Application` serves all files under the given root directory
|
79
|
+
# using `RackStaticApp::Static`. If a file/path doen't exist, `RackStaticApp::NotFound`
|
80
|
+
# is run, which always returns a status of `404` and the contents of
|
81
|
+
# `404.html` or `'Not Found'` if one does not exist.
|
82
|
+
#
|
83
|
+
# Examples
|
84
|
+
#
|
85
|
+
# run RackStaticApp::Application.new('_site')
|
86
|
+
#
|
87
|
+
# run RackStaticApp::Application.new # The root defaults to 'public'
|
88
|
+
#
|
89
|
+
|
90
|
+
class Application < Vienna::Application
|
91
|
+
def initialize(root = 'public')
|
92
|
+
@app = Rack::Builder.new do
|
93
|
+
use Static, root
|
94
|
+
run NotFound.new("#{root}/404.html")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'rackstaticapp/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rackstaticapp"
|
7
|
+
s.version = RackStaticApp::VERSION
|
8
|
+
s.summary = "An update to the Vienna, a tiny zero-config rack app to serve static files"
|
9
|
+
s.description = "A tiny zero-config Rack App to serve static files"
|
10
|
+
s.authors = ["Ronald Ip", "Mikael Konutgan"]
|
11
|
+
s.email = "myself@iphoting.com"
|
12
|
+
s.homepage =
|
13
|
+
"https://rubygems.org/gems/rackstaticapp"
|
14
|
+
s.license = "MIT"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.executables = s.files.grep(/^bin\//) { |f| File.basename(f) }
|
18
|
+
s.test_files = s.files.grep(/^(test|spec|features)\//)
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
s.add_runtime_dependency 'rack', '~> 2.0'
|
22
|
+
s.add_runtime_dependency 'vienna', '~> 0.4.0'
|
23
|
+
|
24
|
+
s.add_development_dependency 'bundler', '~> 2.0'
|
25
|
+
s.add_development_dependency 'rake', '~> 12.0'
|
26
|
+
s.add_development_dependency 'minitest', '~> 5.0'
|
27
|
+
s.add_development_dependency 'yard', '~> 0.9'
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
404
|
@@ -0,0 +1 @@
|
|
1
|
+
about
|
@@ -0,0 +1 @@
|
|
1
|
+
style
|
@@ -0,0 +1 @@
|
|
1
|
+
image
|
@@ -0,0 +1 @@
|
|
1
|
+
index
|
data/spec/spec.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'rack/mock'
|
3
|
+
require 'rackstaticapp'
|
4
|
+
|
5
|
+
describe RackStaticApp do
|
6
|
+
before do
|
7
|
+
app = Rack::Builder.new do
|
8
|
+
use Rack::Lint
|
9
|
+
run RackStaticApp
|
10
|
+
end
|
11
|
+
|
12
|
+
@request = Rack::MockRequest.new(app)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'when requesting the root directory' do
|
16
|
+
before do
|
17
|
+
@res = @request.get('/')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should serve the index path' do
|
21
|
+
_(@res.body.chomp).must_equal 'index'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should return a valid status code, that is 200: OK or 304: Not Modified' do
|
25
|
+
_([200, 304]).must_include @res.status
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'when requesting the path of a subdirectory of the root directory' do
|
30
|
+
before do
|
31
|
+
@paths = {
|
32
|
+
'/css/style.css' => 'style',
|
33
|
+
'/images/image.svg' => 'image',
|
34
|
+
'/about.html' => 'about'
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should serve the contents of the paths' do
|
39
|
+
@paths.each do |path, body|
|
40
|
+
_(@request.get(path).body.chomp).must_equal body
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should cache all responses for a an hour' do
|
45
|
+
@paths.each do |path, body|
|
46
|
+
_(@request.get(path).headers['Cache-Control']).must_equal 'public, max-age=3600'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'when requesting a path that does not exist' do
|
52
|
+
before do
|
53
|
+
@res = @request.get('/path')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should serve the contents of `404.html` if the file exists' do
|
57
|
+
_(@res.body.chomp).must_equal '404'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should return the status code 404: Not Found' do
|
61
|
+
_(@res.status).must_equal 404
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rackstaticapp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ronald Ip
|
8
|
+
- Mikael Konutgan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-09-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: vienna
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.4.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.4.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '2.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '12.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '12.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: minitest
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '5.0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '5.0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: yard
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0.9'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.9'
|
98
|
+
description: A tiny zero-config Rack App to serve static files
|
99
|
+
email: myself@iphoting.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".github/workflows/release.yml"
|
105
|
+
- ".github/workflows/test.yml"
|
106
|
+
- ".gitignore"
|
107
|
+
- ".ruby-version"
|
108
|
+
- CHANGELOG.md
|
109
|
+
- Gemfile
|
110
|
+
- Rakefile
|
111
|
+
- lib/rackstaticapp.rb
|
112
|
+
- lib/rackstaticapp/version.rb
|
113
|
+
- rackstaticapp.gemspec
|
114
|
+
- spec/public/404.html
|
115
|
+
- spec/public/about.html
|
116
|
+
- spec/public/css/style.css
|
117
|
+
- spec/public/images/image.svg
|
118
|
+
- spec/public/index.html
|
119
|
+
- spec/spec.rb
|
120
|
+
homepage: https://rubygems.org/gems/rackstaticapp
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubygems_version: 3.4.10
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: An update to the Vienna, a tiny zero-config rack app to serve static files
|
143
|
+
test_files:
|
144
|
+
- spec/public/404.html
|
145
|
+
- spec/public/about.html
|
146
|
+
- spec/public/css/style.css
|
147
|
+
- spec/public/images/image.svg
|
148
|
+
- spec/public/index.html
|
149
|
+
- spec/spec.rb
|