Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rushsteve1/plug_cgi
A Plug adapter for the Common Gateway Interface
https://github.com/rushsteve1/plug_cgi
Last synced: 24 days ago
JSON representation
A Plug adapter for the Common Gateway Interface
- Host: GitHub
- URL: https://github.com/rushsteve1/plug_cgi
- Owner: rushsteve1
- License: mit
- Created: 2022-03-26T21:48:11.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-11T18:50:26.000Z (almost 2 years ago)
- Last Synced: 2024-12-17T20:15:55.089Z (about 1 month ago)
- Language: Elixir
- Size: 16.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Plug_CGI
[Hex Package](https://hex.pm/packages/plug_cgi)
[Hex Docs](https://hexdocs.pm/plug_cgi)A Plug adapter for the Common Gateway Interface,
allowing you to use all your favorite middleware and tools with the simplicity
of CGI web servers.See the [Plug documentation](https://hexdocs.pm/plug/) for more information.
- https://datatracker.ietf.org/doc/html/rfc3875
- https://en.wikipedia.org/wiki/Common_Gateway_Interface## Example
There are more examples in the
[`cgi-bin` folder](https://github.com/rushsteve1/plug_cgi/tree/main/cgi-bin).```elixir
#!/usr/bin/env elixir# Install plug_cgi as a dependency
Mix.install([
:plug_cgi
])# Define your plug
# You can use middleware, routing, or anything else
defmodule MyPlug do
import Plug.Conndef init(options) do
# initialize options
options
enddef call(conn, _opts) do
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, "Hello world")
end
end# Run your plug with plug_cgi
Plug.CGI.run MyPlug
```## Installation
The package can be installed by adding `plug_cgi` to your list of dependencies
in `mix.exs`:```elixir
def deps do
[
{:plug_cgi, "~> 0.1.0"}
]
end
```## Single-File Elixir Scripts
You can use `plug_cgi` in
[single-file Elixir scripts](https://fly.io/phoenix-files/single-file-elixir-scripts/)
by adding it to your `Mix.install/2` call:```elixir
Mix.install([
:plug_cgi,
])
```When using single-file scripts with CGI you may need to set your `HOME`
environment variable. This can be done by editing the shebang line to:```sh
#!/usr/bin/env HOME=/home/user elixir
```