grape-starter 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/starter/version.rb +1 -1
- data/template/README.md +5 -4
- data/template/Rakefile +1 -1
- data/template/api/base.rb +1 -0
- data/template/config.ru +1 -5
- data/template/config/application.rb +17 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d549f6e5ecd48d20c126a63de91a14ac9fb9262f
|
4
|
+
data.tar.gz: 33174fb1dd003ee55acbe824a96c2a56588c4d55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c42c646d1248bd7d953049ddd80ae019ebe4df5220fddfd025e60c9910809009d2c8d7725472c53b7ac4307551c34ced33c5c3831002145587627887d4450c98
|
7
|
+
data.tar.gz: 458945f18afcf926a97624405ec0591ec3adf5068776ad5746865bb85d827639a0a435980a7dfcac2125b1907fd98bbc42e4b883bdb93bfdf4b265a67882eb65
|
data/README.md
CHANGED
@@ -60,7 +60,7 @@ $ cd awesome_api
|
|
60
60
|
$ ./script/server *port
|
61
61
|
```
|
62
62
|
the API is now accessible under: [http://localhost:9292/api/v1/root](http://localhost:9292/api/v1/root)
|
63
|
-
the documentation of it under: [http://localhost:9292/](http://localhost:9292/)
|
63
|
+
the documentation of it under: [http://localhost:9292/](http://localhost:9292/).
|
64
64
|
|
65
65
|
More could be found in [README](template/README.md).
|
66
66
|
|
data/lib/starter/version.rb
CHANGED
data/template/README.md
CHANGED
@@ -24,13 +24,14 @@ $ ./script/test
|
|
24
24
|
#### Run
|
25
25
|
|
26
26
|
```
|
27
|
-
$ ./script/server
|
27
|
+
$ ./script/server *port (default: 9292)
|
28
28
|
```
|
29
|
-
and go to: [http://localhost:
|
29
|
+
and go to: [http://localhost:port/](http://localhost:9292/)
|
30
|
+
to access the OAPI documentation.
|
30
31
|
|
31
|
-
|
32
|
+
For production, set `RACK_ENV=production`
|
32
33
|
```
|
33
|
-
$
|
34
|
+
$ RACK_ENV=production ./script/server *port (default: 9292)
|
34
35
|
```
|
35
36
|
|
36
37
|
#### Update
|
data/template/Rakefile
CHANGED
data/template/api/base.rb
CHANGED
data/template/config.ru
CHANGED
@@ -22,18 +22,12 @@ end
|
|
22
22
|
require 'base'
|
23
23
|
|
24
24
|
require 'rack'
|
25
|
-
|
26
25
|
# provides the documentation of the API
|
27
26
|
class DocApp
|
27
|
+
attr_reader :env
|
28
28
|
def call(env)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def re_doc(env)
|
33
|
-
doc = template.sub('{{{server}}}', env['SERVER_NAME'])
|
34
|
-
doc = doc.sub('{{{port}}}', env['SERVER_PORT'])
|
35
|
-
|
36
|
-
doc
|
29
|
+
@env = env
|
30
|
+
[200, { 'Content-Type' => 'text/html' }, [template]]
|
37
31
|
end
|
38
32
|
|
39
33
|
def template
|
@@ -42,19 +36,22 @@ class DocApp
|
|
42
36
|
<head>
|
43
37
|
<title>ReDoc API documentation</title>
|
44
38
|
<meta name='viewport' content='width=device-width, initial-scale=1'>
|
45
|
-
<style>
|
46
|
-
body {
|
47
|
-
margin: 0;
|
48
|
-
padding: 0;
|
49
|
-
}
|
50
|
-
</style>
|
39
|
+
<style>body {margin: 0;padding: 0;}</style>
|
51
40
|
</head>
|
52
41
|
<body>
|
53
|
-
<redoc spec-url='http
|
42
|
+
<redoc spec-url='http://#{server}:#{port}/#{Api::Base.prefix}/#{Api::Base.version}/oapi.json'></redoc>
|
54
43
|
<script src='https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js'> </script>
|
55
44
|
</body>
|
56
45
|
</html>"
|
57
46
|
end
|
47
|
+
|
48
|
+
def server
|
49
|
+
@env['SERVER_NAME']
|
50
|
+
end
|
51
|
+
|
52
|
+
def port
|
53
|
+
@env['SERVER_PORT']
|
54
|
+
end
|
58
55
|
end
|
59
56
|
|
60
57
|
# provides the routing between the API and the html documentation of it
|
@@ -63,16 +60,11 @@ class App
|
|
63
60
|
@apps = {}
|
64
61
|
end
|
65
62
|
|
66
|
-
def map(route, app)
|
67
|
-
@apps[route] = app
|
68
|
-
end
|
69
|
-
|
70
63
|
def call(env)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
@apps[request.path].call(env)
|
64
|
+
if env['REQUEST_PATH'].start_with?("/#{Api::Base.prefix}")
|
65
|
+
Api::Base.call(env)
|
66
|
+
else
|
67
|
+
DocApp.new.call(env)
|
76
68
|
end
|
77
69
|
end
|
78
70
|
end
|