Skip to content

Commit 3397147

Browse files
committed
add-dependencies
1 parent c24af29 commit 3397147

File tree

3 files changed

+70
-43
lines changed

3 files changed

+70
-43
lines changed

Diff for: README.md

+65-41
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,10 @@ npm create resty-app@latest -y
1111
```
1212
Then follow the instructions to complete the project.
1313

14-
# Api
15-
16-
## new
17-
18-
```lua
19-
(method) Router:new()
20-
-> Router
21-
```
22-
23-
create a router.
24-
25-
## insert
14+
# Dependencies
2615

27-
```lua
28-
(method) Router:insert(path: string, handler: string|function, methods?: string|string[])
29-
-> Router
30-
```
31-
32-
insert a route.
33-
34-
## extend
35-
36-
```lua
37-
---@alias Route {[1]:string, [2]:function|string, [3]?:string|string[]}
38-
(method) Router:extend(routes: Route[])
39-
-> Router
40-
```
41-
42-
insert routes to a router.
43-
44-
## match
45-
46-
```lua
47-
(method) Router:match(path: string, method: string)
48-
-> string|function
49-
2. { [string]: string|number }?
50-
```
51-
52-
match a http request
16+
* [OpenResty](https://openresty.org/)
17+
* (Optional) [lfs](https://luarocks.org/modules/hisham/luafilesystem) or [syscall.lfs](https://github.com/justincormack/ljsyscall) - if you want to use `fs` method to load routes from directory
5318

5419
# Synopsis
5520

@@ -62,6 +27,7 @@ local cnt = 0
6227
local error_cnt = 0
6328

6429
-- Test events
30+
-- for test purpose, assume the nginx is single-threaded
6531
router:on('add', function(ctx)
6632
cnt = cnt + 1
6733
end)
@@ -169,7 +135,7 @@ end)
169135
router:get("/func", function(ctx)
170136
return function()
171137
ngx.header.content_type = 'text/plain; charset=utf-8'
172-
ngx.say("function called2")
138+
ngx.say("function called")
173139
end
174140
end)
175141

@@ -186,6 +152,64 @@ end)
186152
return router
187153

188154
```
189-
## reference
190155

191-
- [nginx api for lua](https://github.com/openresty/lua-nginx-module?tab=readme-ov-file#nginx-api-for-lua)
156+
# Api
157+
158+
## new
159+
160+
```lua
161+
(method) Router:new()
162+
-> Router
163+
```
164+
165+
create a router.
166+
167+
## insert
168+
169+
```lua
170+
(method) Router:insert(path: string, handler: string|function, methods?: string|string[])
171+
-> Router
172+
```
173+
174+
insert a route.
175+
176+
## extend
177+
178+
```lua
179+
---@alias Route {[1]:string, [2]:function|string, [3]?:string|string[]}
180+
(method) Router:extend(routes: Route[])
181+
-> Router
182+
```
183+
184+
insert routes to a router.
185+
186+
## match
187+
188+
```lua
189+
(method) Router:match(path: string, method: string)
190+
->
191+
1. string|function
192+
2. { [string]: string|number }?
193+
```
194+
195+
match a http request
196+
197+
## run
198+
```lua
199+
(method) Router:run()
200+
-> nil
201+
```
202+
dispatch http request
203+
204+
## fs
205+
206+
```lua
207+
(method) Router:fs(dir: string)
208+
-> nil
209+
```
210+
211+
load routes from directory (requires `lfs` or `syscall.lfs` module).
212+
213+
# reference
214+
215+
- [nginx api for lua](https://github.com/openresty/lua-nginx-module?tab=readme-ov-file#nginx-api-for-lua)

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-resty-app",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"description": "high performance router",
55
"type": "module",
66
"bin": {

Diff for: template/app.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ router:get('/', function(ctx)
7171
<div class="container">
7272
<h1>🎉🎉🎉🎉 Congratulations!</h1>
7373
<p>Your resty application is running</p>
74+
<p>Here are some example routes (requires `lfs` or `syscall.lfs` module):</p>
7475
<div class="api-list">
7576
<div class="api-item">
7677
<a href="/test/hello"><span class="method">GET</span> /test/hello - Simple String Response</a>
@@ -101,6 +102,8 @@ router:get('/', function(ctx)
101102
end)
102103

103104
-- add routes from lua files in api folder
104-
router:fs('./api')
105+
if pcall(require, "syscall.lfs") or pcall(require, "lfs") then
106+
router:fs('./api')
107+
end
105108

106109
return router

0 commit comments

Comments
 (0)