httpme 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +63 -0
- data/bin/httpme +14 -0
- data/lib/httpme.rb +2 -0
- data/lib/httpme/cli.rb +9 -0
- data/lib/httpme/command.rb +41 -0
- data/lib/httpme/server.rb +49 -0
- data/lib/httpme/version.rb +3 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c36c1d9a162dd656edeedabcaede1013f203df65d486908901545894c4d2da70
|
4
|
+
data.tar.gz: 1927215e0164392810328e76758a11dc8b58822b47d1dd4d8bd56af0881317fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f2ba944c4077805f1850cfe14886fbb0b9491096d5ea4d9e1782ca1b1d2b16d149474e9ac087f86b18c4ded5455c140c146990022d292991ae71adb469a3cef
|
7
|
+
data.tar.gz: bb79c9deb998a6c79faabb7cf2e26efe74949d8b12b06c8a31a23520433a14f4e8eb41c5c1189cd462defad6cf943a7debd8e15f19ef81b8a40e756229b2d679
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# HTTPMe
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/httpme)
|
4
|
+
[](https://github.com/DannyBen/victor/actions?query=workflow%3ATest)
|
5
|
+
|
6
|
+
---
|
7
|
+
|
8
|
+
Static files web server with basic authentication.
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
$ gem install httpme
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
|
19
|
+
```shell
|
20
|
+
httpme - static web server with basic authentication
|
21
|
+
|
22
|
+
Options can be set using command line arguments or environment variables
|
23
|
+
|
24
|
+
Usage:
|
25
|
+
httpme [PATH] [--port PORT --host HOST --auth AUTH]
|
26
|
+
httpme (-h|--help)
|
27
|
+
|
28
|
+
Options:
|
29
|
+
-p, --port PORT
|
30
|
+
Server port (default: 3000)
|
31
|
+
|
32
|
+
-o, --host HOST
|
33
|
+
Server host (default: 0.0.0.0)
|
34
|
+
|
35
|
+
-a, --auth AUTH
|
36
|
+
Specify user:password to enable basic authentication
|
37
|
+
|
38
|
+
-h --help
|
39
|
+
Show this help
|
40
|
+
|
41
|
+
Parameters:
|
42
|
+
PATH
|
43
|
+
Path to the directory you want to serve [default: .]
|
44
|
+
|
45
|
+
Environment Variables:
|
46
|
+
HTTPME_PATH
|
47
|
+
Same as --path
|
48
|
+
|
49
|
+
HTTPME_AUTH
|
50
|
+
Same as --auth
|
51
|
+
|
52
|
+
HTTPME_PORT
|
53
|
+
Same as --port
|
54
|
+
|
55
|
+
HTTPME_HOST
|
56
|
+
Same as --host
|
57
|
+
|
58
|
+
Examples:
|
59
|
+
httpme -p 3000
|
60
|
+
httpme docs --auth admin:s3cr3t
|
61
|
+
HTTPME_AUTH=admin:s3cr3t httpme docs # same result as above
|
62
|
+
```
|
63
|
+
|
data/bin/httpme
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'httpme'
|
3
|
+
require 'httpme/cli'
|
4
|
+
include Colsole
|
5
|
+
|
6
|
+
router = HTTPMe::CLI.router
|
7
|
+
|
8
|
+
begin
|
9
|
+
exit router.run ARGV
|
10
|
+
rescue => e
|
11
|
+
puts e.backtrace.reverse if ENV['DEBUG']
|
12
|
+
say! "!txtred!#{e.class}: #{e.message}"
|
13
|
+
exit 1
|
14
|
+
end
|
data/lib/httpme.rb
ADDED
data/lib/httpme/cli.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'mister_bin'
|
2
|
+
require 'colsole'
|
3
|
+
|
4
|
+
module HTTPMe
|
5
|
+
class Command < MisterBin::Command
|
6
|
+
include Colsole
|
7
|
+
|
8
|
+
summary "httpme - static web server with basic authentication"
|
9
|
+
|
10
|
+
help "Options can be set using command line arguments or environment variables"
|
11
|
+
|
12
|
+
usage "httpme [PATH] [--port PORT --host HOST --auth AUTH]"
|
13
|
+
usage "httpme (-h|--help)"
|
14
|
+
|
15
|
+
param "PATH", "Path to the directory you want to serve [default: .]"
|
16
|
+
option "-p, --port PORT", "Server port (default: 3000)"
|
17
|
+
option "-o, --host HOST", "Server host (default: 0.0.0.0)"
|
18
|
+
option "-a, --auth AUTH", "Specify user:password to enable basic authentication"
|
19
|
+
|
20
|
+
environment 'HTTPME_PATH', "Same as --path"
|
21
|
+
environment 'HTTPME_AUTH', "Same as --auth"
|
22
|
+
environment 'HTTPME_PORT', "Same as --port"
|
23
|
+
environment 'HTTPME_HOST', "Same as --host"
|
24
|
+
|
25
|
+
example "httpme -p 3000"
|
26
|
+
example "httpme docs --auth admin:s3cr3t"
|
27
|
+
example "HTTPME_AUTH=admin:s3cr3t httpme docs # same result as above"
|
28
|
+
|
29
|
+
def run
|
30
|
+
path = args['PATH'] || ENV['HTTPME_PATH'] || '.'
|
31
|
+
port = (args['--port'] || ENV['HTTPME_PORT'] || 3000).to_i
|
32
|
+
host = args['--host'] || ENV['HTTPME_HOST'] || '0.0.0.0'
|
33
|
+
auth = args['--auth'] || ENV['HTTPME_AUTH']
|
34
|
+
|
35
|
+
raise ArgumentError, "Path not found [#{path}]" unless Dir.exist? path
|
36
|
+
|
37
|
+
server = Server.new path: path, host: host, port: port, auth: auth
|
38
|
+
server.run
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'rack/handler/puma'
|
3
|
+
|
4
|
+
module HTTPMe
|
5
|
+
class Server
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
Rack::Handler::Puma.run(app, rack_options) do |server|
|
14
|
+
# :nocov: - FIXME: Can we test this?
|
15
|
+
[:INT, :TERM].each do |sig|
|
16
|
+
trap(sig) { server.stop }
|
17
|
+
end
|
18
|
+
# :nocov:
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def app
|
23
|
+
path = options[:path] || '.'
|
24
|
+
auth = options[:auth]
|
25
|
+
zone = options[:zone] || 'Restricted Area'
|
26
|
+
|
27
|
+
Rack::Builder.new do
|
28
|
+
if auth
|
29
|
+
use Rack::Auth::Basic, zone do |username, password|
|
30
|
+
auth.split(':') == [username, password]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
use Rack::Static, urls: ["/"], root: path, cascade: true, index: 'index.html'
|
35
|
+
run Rack::Directory.new(path)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def rack_options
|
42
|
+
{
|
43
|
+
Port: (options[:port] || '3000'),
|
44
|
+
Host: (options[:host] || '0.0.0.0'),
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: httpme
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danny Ben Shitrit
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mister_bin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colsole
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: puma
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.3'
|
69
|
+
description: Command line utility for running a web server for static files with basic
|
70
|
+
authentication support
|
71
|
+
email: db@dannyben.com
|
72
|
+
executables:
|
73
|
+
- httpme
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- README.md
|
78
|
+
- bin/httpme
|
79
|
+
- lib/httpme.rb
|
80
|
+
- lib/httpme/cli.rb
|
81
|
+
- lib/httpme/command.rb
|
82
|
+
- lib/httpme/server.rb
|
83
|
+
- lib/httpme/version.rb
|
84
|
+
homepage: https://github.com/dannyben/httpme
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.4.0
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubygems_version: 3.0.3
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Static files web server with basic authentication
|
107
|
+
test_files: []
|