From 3a8f293144f129e007e0cbbd4c179cc2cab50c73 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Sat, 17 May 2025 15:01:29 -0700 Subject: [PATCH] WIP: routing --- Dockerfile | 1 + conf/nginx.conf | 18 +++++++++++++++--- routes.lua | 6 ++++++ routes.moon | 7 +++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 routes.lua create mode 100644 routes.moon diff --git a/Dockerfile b/Dockerfile index 008bcbf..5e58cd3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ FROM openresty/openresty:1.27.1.2-0-bookworm-buildpack WORKDIR /opt/app RUN apt-get update && apt-get install -y python3-pygments pandoc lua-inotify +RUN opm get DevonStrawn/lua-resty-route RUN luarocks install sitegen RUN luarocks install inotify INOTIFY_INCDIR=/usr/include/x86_64-linux-gnu/ diff --git a/conf/nginx.conf b/conf/nginx.conf index 46f0136..57ae3f5 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,9 +1,15 @@ worker_processes 1; error_log logs/error.log; + events { worker_connections 1024; } + http { + init_by_lua_block { + require "routes" + } + server { listen 8080; @@ -12,9 +18,15 @@ http { location / { default_type text/html; - # content_by_lua_block { - # ngx.say("

hello, world

") - # } + } + + location /foo { + default_type text/html; + + rewrite_by_lua_block { + routes = require "routes" + routes:dispatch() + } } location /css { diff --git a/routes.lua b/routes.lua new file mode 100644 index 0000000..8f28922 --- /dev/null +++ b/routes.lua @@ -0,0 +1,6 @@ +local route = require("resty.route").new() +route:get("/foo", function(self) + local uri = "/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html" + return ngx.req.set_uri(uri, true) +end) +return route diff --git a/routes.moon b/routes.moon new file mode 100644 index 0000000..21d81ae --- /dev/null +++ b/routes.moon @@ -0,0 +1,7 @@ +route = require("resty.route").new! + +route\get "/foo", => + uri = "/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html" + ngx.req.set_uri(uri, true) + +route