Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
feat: scripts/run + README run instructions for the OpenResty demo#6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,4 +7,5 @@ node_modules | ||
| .psci | ||
| .spago | ||
| output | ||
| .direnv/ | ||
| .psc-ide-port | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| # Demo runner: serves the compiled Lua.Ngx bindings under OpenResty so you can | ||
| # curl them. The bindings wrap the `ngx.*` API the lua-nginx-module injects, so | ||
| # they only run inside an OpenResty worker (plain `lua` or vanilla nginx will | ||
| # not work). Build first with ./scripts/build, then: | ||
| # | ||
| # nix develop -c ./scripts/run # serve on :8099 | ||
| # PORT=9000 nix develop -c ./scripts/run # pick another port | ||
| # | ||
| # In another terminal: | ||
| # curl http://127.0.0.1:8099/say | ||
| # curl -i http://127.0.0.1:8099/status | ||
| here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
| dist="$here/dist" | ||
| port="${PORT:-8099}" | ||
| # PORT is interpolated into `listen $port;`, so reject anything that is not a | ||
| # plain TCP port number before it reaches the config. | ||
| if ! [[ $port =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then | ||
| echo "PORT must be an integer in 1..65535 (got: '$port')." >&2 | ||
| exit 1 | ||
| fi | ||
| if ! command -v openresty >/dev/null 2>&1; then | ||
| echo "openresty is not on PATH." >&2 | ||
| echo "Run inside the dev shell: nix develop -c ./scripts/run" >&2 | ||
| echo "(With direnv, reload it after pulling: direnv reload)" >&2 | ||
| exit 1 | ||
| fi | ||
| # Both modules are served below (/say and /status), and both come from the same | ||
| # ./scripts/build run, so fail fast if either is missing rather than only at the | ||
| # first request that needs it. | ||
| for f in Lua.Ngx.lua Lua.Ngx.Http.Status.lua; do | ||
| if [ ! -f "$dist/$f" ]; then | ||
| echo "dist/$f is missing. Run ./scripts/build first." >&2 | ||
| exit 1 | ||
| fi | ||
| done | ||
| work="$(mktemp -d)" | ||
| trap 'rm -rf "$work"' EXIT | ||
| mkdir -p "$work/logs" | ||
| # A linked dist module is a flat file named e.g. `Lua.Ngx.lua` (a literal dot in | ||
| # the filename, not a path), so consumers load it with dofile by absolute path | ||
| # rather than require, which would rewrite the dot to a directory separator. | ||
| cat > "$work/nginx.conf" <<EOF | ||
| worker_processes 1; | ||
| daemon off; | ||
| error_log stderr info; | ||
| pid $work/logs/nginx.pid; | ||
| events { worker_connections 64; } | ||
| http { | ||
| access_log off; | ||
| lua_code_cache off; # reload the dist on every request while iterating | ||
| client_body_temp_path $work/logs/client_body; | ||
| proxy_temp_path $work/logs/proxy; | ||
| fastcgi_temp_path $work/logs/fastcgi; | ||
| uwsgi_temp_path $work/logs/uwsgi; | ||
| scgi_temp_path $work/logs/scgi; | ||
| server { | ||
| listen $port; | ||
| # Lua.Ngx.say is an Effect (String -> Effect Unit), so the generated value | ||
| # is curried: say(msg) returns a thunk that performs the write when called. | ||
| location /say { | ||
| content_by_lua_block { | ||
| local Ngx = dofile("$dist/Lua.Ngx.lua") | ||
| Ngx.say("hello from purescript-lua-ngx")() | ||
| } | ||
| } | ||
| # Lua.Ngx.Http.Status exposes the HTTP_* constants plus get/set for | ||
| # ngx.status (set is likewise an effectful thunk). | ||
| location /status { | ||
| content_by_lua_block { | ||
| local Ngx = dofile("$dist/Lua.Ngx.lua") | ||
| local Status = dofile("$dist/Lua.Ngx.Http.Status.lua") | ||
| Status.set(Status.notFound)() | ||
| Ngx.say("HTTP_OK constant = " .. tostring(Status.ok))() | ||
| Ngx.say("ngx.status now = " .. tostring(Status.get()))() | ||
| } | ||
| } | ||
| } | ||
| } | ||
| EOF | ||
| echo "Serving compiled Lua.Ngx on http://127.0.0.1:$port" | ||
| echo " curl http://127.0.0.1:$port/say" | ||
| echo " curl -i http://127.0.0.1:$port/status" | ||
| echo "Ctrl-C to stop." | ||
| # -e stderr sets the error log before the config is parsed, so nginx does not | ||
| # try (and noisily fail) to open its compiled-in default /var/log/nginx path. | ||
| openresty -p "$work" -e stderr -c "$work/nginx.conf" | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.