rack-cgi 0.4.1 → 0.4.2
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 +4 -4
- data/README.md +41 -41
- data/lib/rack/cgi/version.rb +1 -1
- 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: 2dcab38b6e1fc83699f610007eac3c3cd7f931fb
|
4
|
+
data.tar.gz: 00abaf13b44be8e28a64d6e027f373276b3d196c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0b1b1b999cbb66b494f705b94885d9bb73f08827be21723214de717c8b692189f3b82c765d1551f97492b648560fe0478c155bda1e3284892d7a81384e3fc8f
|
7
|
+
data.tar.gz: ea0460d72eaf739ffdb21bd03310ceafa1c10232a5f36c4d19320c713de6f0b889f53ba4d513badccd898cbe79ce6e0014748e61f2ab9dc37f1725ed9fa0b117
|
data/README.md
CHANGED
@@ -7,14 +7,14 @@ Usage
|
|
7
7
|
-----
|
8
8
|
|
9
9
|
Here is an example for using Rack::CGI
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
```ruby
|
11
|
+
# config.ru
|
12
|
+
|
13
|
+
use Rack::CGI, cgi_path: 'cgi', index: 'index.cgi', Rack::CGI::Executable => '', /\.php$/ => '/usr/bin/php-cgi'
|
14
|
+
use Rack::Static, urls: ['/'], root: 'cgi'
|
15
|
+
run proc{ [404, {"CONTENT-TYPE" => "text/plain"}, ['404 Not Found']] }
|
16
|
+
```
|
17
|
+
How to
|
18
18
|
-----
|
19
19
|
|
20
20
|
### Document Root
|
@@ -28,20 +28,20 @@ When user access directory, Rack::CGI will use index script instand of.
|
|
28
28
|
If you not special index, Rack::CGI will not have a default value, and it's not works.
|
29
29
|
|
30
30
|
You can special index as follow:
|
31
|
+
```ruby
|
32
|
+
use Rack::CGI, index: 'index.php'
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
use Rack::CGI, index: ['index.php', 'index.cgi']
|
36
|
-
|
34
|
+
# or special multiple, Rack::CGI will try each by order
|
35
|
+
use Rack::CGI, index: ['index.php', 'index.cgi']
|
36
|
+
```
|
37
37
|
### Rules
|
38
38
|
|
39
39
|
When Rack::CGI found a script file in disk, it will try to find a rule to deal it.
|
40
40
|
|
41
41
|
You can special multiple rules, in follow format:
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
```ruby
|
43
|
+
use Rack::CGI, match1 => deal1, match2 => deal2, match3 => deal3 ...
|
44
|
+
```
|
45
45
|
`match` can be Rack::CGI::Executable or Regexp.
|
46
46
|
Rack::CGI::Executable match all script that is executable.
|
47
47
|
Regexp will try to match script full path.
|
@@ -61,9 +61,9 @@ All relative resource will cannot accessed. In this case, we have to redirect 'h
|
|
61
61
|
'http://wps-community.org/forum/' to avoid this problem.
|
62
62
|
|
63
63
|
You can use following code to open this feature.
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
```ruby
|
65
|
+
use Rack::CGI, ..., dir_redirect: true, ...
|
66
|
+
```
|
67
67
|
### Use Rack::CGI in Rails project
|
68
68
|
|
69
69
|
Originally I intended to write a project named rails-cgi.
|
@@ -71,31 +71,31 @@ But it's so trouble, and run Rack app in rails is not very complex.
|
|
71
71
|
So I give up rails-cgi.
|
72
72
|
|
73
73
|
1. Create a cgi controller
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
```bash
|
75
|
+
$ rails g controller cgi
|
76
|
+
```
|
77
77
|
2. Create a Rack Application in CgiController
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
78
|
+
```ruby
|
79
|
+
# You can changed arguments as you want
|
80
|
+
CGI = Rack::Builder.new do
|
81
|
+
use Rack::CGI, cgi_path: 'cgi', index: ['index.cgi', 'index.php'], Rack::CGI::Executable => '', /\.php$/ => '/usr/bin/php-cgi'
|
82
|
+
use Rack::Static, urls: ['/'], root: 'cgi'
|
83
|
+
run proc{ |env| raise ActionController::RoutingError, env['PATH_INFO'] + " not found!" }
|
84
|
+
end
|
85
|
+
```
|
86
86
|
3. Call Rack App in rails controller
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
87
|
+
```ruby
|
88
|
+
# add an action to controller
|
89
|
+
def cgi
|
90
|
+
[self.status, self.response.headers, self.response_body] = CGI.call env
|
91
|
+
end
|
92
|
+
# of course, you can add decoration code here, such as call rails layout
|
93
|
+
```
|
94
94
|
4. Add route
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
95
|
+
```ruby
|
96
|
+
# add follow to config/routes.rb
|
97
|
+
get '/cgi-bin/*path' => 'cgi#cgi'
|
98
|
+
```
|
99
99
|
TODO
|
100
100
|
----
|
101
101
|
|
data/lib/rack/cgi/version.rb
CHANGED