Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/publica-re/phoenix_cgi
A small CGI controller for Phoenix
https://github.com/publica-re/phoenix_cgi
cgi elixir phoenix
Last synced: about 1 month ago
JSON representation
A small CGI controller for Phoenix
- Host: GitHub
- URL: https://github.com/publica-re/phoenix_cgi
- Owner: publica-re
- License: gpl-3.0
- Created: 2020-08-30T13:57:02.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-30T14:10:54.000Z (over 4 years ago)
- Last Synced: 2024-10-30T00:34:11.955Z (3 months ago)
- Topics: cgi, elixir, phoenix
- Language: Elixir
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PhoenixCGI
A small CGI controller for Phoenix.
---
## Setup
Add `PhoenixCGI` to your `deps` in `mix.exs`:
```elixir
defp deps do
[
{:phoenix_cgi, "~> 0.1"},
...
]
end
```then, and that's really important, in your `endpoint.ex`, add the following `body_reader` in your `plug Plug.Parsers`:
```elixir
plug Plug.Parsers,
body_reader: {PhoenixCGI.CacheRawBody, :read_body, []},
...
```This will cause the body of your request to be saved in a private field, so that we will be able to
pass it to the CGI scripts.## Usage
You will then be able to use `PhoenixCGI` as any controller. For instance, if you want to serve `git-http-backend` on a
`/git/` to serve all repositories in `/opt/git/repos/`, you can setup as follows:```elixir
match :*, "/git/*path", PhoenixCGI,
binary: "/usr/lib/git-core/git-http-backend",
extra_env: %{
GIT_PROJECT_ROOT: "/opt/git/repos/",
GIT_HTTP_EXPORT_ALL: "1"
}
```You can also define a plug that will define, for instance, which project to serve, with `assign/3`.
```elixir
defp set_repo(conn) do
assign(conn, :extra_env, %{
GIT_PROJECT_ROOT: "/opt/git/repos/demo.git",
GIT_HTTP_EXPORT_ALL: "1"
})
end
```and then use it
```elixir
pipeline :git do
plug :set_repo
endscope "/" do
pipe_through :gitmatch :*, "/git/*path", PhoenixCGI,
binary: "/usr/lib/git-core/git-http-backend"
end
```## Documentation
The documentation is available on [hexdocs](https://hexdocs.pm/phoenix_cgi/0.1.0/PhoenixCGI.html#content).
## Licence
Copyright (C) 2020 David Baumgartner
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.You should have received a copy of the GNU General Public License along
with this program. If not, see .## Contribution
I happily accept pull requests through [GitHub](https://github.com/publica-re/phoenix_cgi).