WIP: routes???
This commit is contained in:
parent
6a634ceea3
commit
8a92d0451b
@ -16,22 +16,39 @@ http {
|
|||||||
include mime.types;
|
include mime.types;
|
||||||
charset utf-8;
|
charset utf-8;
|
||||||
|
|
||||||
location / {
|
location = /posts {
|
||||||
default_type text/html;
|
# rewrite ^ /posts/ last; # loads "/posts/"
|
||||||
}
|
# rewrite ^ /posts/ break; # loads "/posts/index.html"
|
||||||
|
|
||||||
location /foo {
|
|
||||||
default_type text/html;
|
|
||||||
|
|
||||||
rewrite_by_lua_block {
|
rewrite_by_lua_block {
|
||||||
routes = require "routes"
|
-- equivalent to `rewrite ^ /posts/ break;`
|
||||||
routes:dispatch()
|
ngx.req.set_uri("/posts/", false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location = /posts/ {
|
||||||
|
content_by_lua_block {
|
||||||
|
return ngx.redirect("/posts", ngx.HTTP_MOVED_PERMANENTLY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
location /posts/ {
|
||||||
|
content_by_lua_block {
|
||||||
|
require "routes":dispatch()
|
||||||
|
-- ngx.req.set_uri("/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html")
|
||||||
|
-- ngx.req.set_uri(ngx.var.uri, false)
|
||||||
|
-- ngx.req.set_uri("/posts/index.html", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
# rewrite ^ /posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html break;
|
||||||
|
}
|
||||||
|
|
||||||
location /css {
|
location /css {
|
||||||
expires 1h;
|
expires 1h;
|
||||||
alias css;
|
alias css;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /blah {
|
||||||
|
rewrite ^/posts$ /posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
local route = require("resty.route").new()
|
local route = require("resty.route").new()
|
||||||
route:get("/foo", function(self)
|
route:get("=/posts/index.html", function(self)
|
||||||
local uri = "/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html"
|
return ngx.exec("/posts/index.html")
|
||||||
return ngx.req.set_uri(uri, true)
|
end)
|
||||||
|
route:get("=/posts/", function(self)
|
||||||
|
return ngx.req.set_uri("/posts/index.html", false)
|
||||||
end)
|
end)
|
||||||
return route
|
return route
|
||||||
|
52
routes.moon
52
routes.moon
@ -1,7 +1,53 @@
|
|||||||
route = require("resty.route").new!
|
route = require("resty.route").new!
|
||||||
|
|
||||||
route\get "/foo", =>
|
-- flag = last: true, break: false
|
||||||
uri = "/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html"
|
|
||||||
ngx.req.set_uri(uri, true)
|
route\get "=/posts/index.html", =>
|
||||||
|
-- ngx.req.set_uri("/posts/index.html", false)
|
||||||
|
ngx.exec("/posts/index.html")
|
||||||
|
|
||||||
|
route\get "=/posts/", =>
|
||||||
|
-- ngx.req.set_uri("/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html", false)
|
||||||
|
-- ngx.exec("/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html")
|
||||||
|
-- ngx.say("resty-route " .. ngx.var.uri)
|
||||||
|
-- ngx.req.set_uri(ngx.var.uri, false)
|
||||||
|
-- @render "somecontent", @context
|
||||||
|
ngx.req.set_uri("/posts/index.html", false)
|
||||||
|
-- ngx.req.set_uri("/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html", true)
|
||||||
|
-- ngx.say ngx.var.uri
|
||||||
|
-- ngx.exec("/about.html")
|
||||||
|
-- ngx.exec("/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html")
|
||||||
|
|
||||||
|
-- route\get "#/posts/([%w%-%_]+)[.](%w+)", (file, ext) =>
|
||||||
|
-- ngx.req.set_uri("/posts")
|
||||||
|
-- ngx.say ngx.var.uri
|
||||||
|
-- ngx.exec "/posts/#{file}.#{ext}"
|
||||||
|
-- ngx.req.set_uri("/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html")
|
||||||
|
|
||||||
|
-- route\get "#/posts/([%w%-%_]+)", (id) =>
|
||||||
|
-- ngx.say "<p>hello</p>"
|
||||||
|
-- route\get "#/posts/(%w+)", (id) =>
|
||||||
|
-- ngx.say file
|
||||||
|
-- ngx.exec "/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html"
|
||||||
|
|
||||||
|
-- route\get "=/posts", =>
|
||||||
|
-- route\get "#/posts/([%w%-%_]+)", (id) =>
|
||||||
|
-- ngx.exec "/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html"
|
||||||
|
-- ngx.req.set_uri("/posts")
|
||||||
|
-- ngx.exec "/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html"
|
||||||
|
-- router\to "/about.html", "get"
|
||||||
|
-- require("moon").p route
|
||||||
|
-- { one: "two" }
|
||||||
|
-- ngx.say [k .. v for k, v in pairs { one: "two" }]
|
||||||
|
-- keys = [k .. "\n" for k,v in pairs @]
|
||||||
|
-- keys = [k .. "\n" for k,v in pairs @]
|
||||||
|
-- ngx.log(ngx.ERR, @)
|
||||||
|
|
||||||
|
-- ngx.say [k .. v for k, v in pairs route]
|
||||||
|
-- ngx.say type(route)
|
||||||
|
-- uri = "/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html"
|
||||||
|
-- ngx.req.set_uri("/about.html")
|
||||||
|
-- ngx.say "<p>/posts</p>"
|
||||||
|
-- @to "/", "get"
|
||||||
|
|
||||||
route
|
route
|
||||||
|
Loading…
x
Reference in New Issue
Block a user