Skip to content

Commit 945815d

Browse files
committed
Fix middleware composition
1 parent cc18cfa commit 945815d

14 files changed

Lines changed: 95 additions & 5 deletions

File tree

TODO.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
## Immediate
22

3+
- [ ] Testing
4+
- [v] A module that exports a proc that takes 2 args, or maybe kwargs, how
5+
does the system deal with that?
6+
- [ ] middleware hook composition
7+
- [ ] Scenario with multiple hooks on different levels
8+
- [ ] error handler
9+
- [ ] Scenario with multiple error handlers on different levels
10+
- [ ] Controllers
11+
- [ ] Streamline names of ready-made control methods:
12+
- [ ] dispatch_by_host('.', mapping:) - currently `route_by_hosst`
13+
- [ ] dispatch_by_http_method - currently `http_methods`
14+
- [ ] dispatch_json_rpc
15+
316
- [ ] Collection - treat directories and files as collections of data.
417

518
Kind of similar to the routing tree, but instead of routes it just takes a

lib/syntropy/module_loader.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ def load_module(ref, raise_on_missing: true)
150150
# @param ref [String] input ref
151151
# @return [String] clean ref
152152
def clean_ref(ref)
153-
return '/' if ref =~ /^index(\+)?$/
153+
return '/' if ref =~ /^index[+]?$/
154154

155-
clean = ref.gsub(/\/index(?:\+)?$/, '')
156-
clean == '' ? '/' : clean
155+
clean = ref.gsub(/\/index[+]?$/, '')
156+
(clean == '') ? '/' : clean
157157
end
158158

159159
# Transforms the given export value. If the value is nil, an exception is

lib/syntropy/routing_tree.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ def set_index_route_target(parent:, path:, kind:, fn:, handle_subtree: nil)
339339
target: { kind:, fn: },
340340
# In case we're at the tree root, we need to copy over the hook and
341341
# error refs.
342-
hook: !parent[:parent] && parent[:hook],
343-
error: !parent[:parent] && parent[:error]
342+
hook: parent[:hook],
343+
error: parent[:error]
344344
}
345345
end
346346
nil

test/fixtures/app/bad_mod_arity.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export ->(req, blah) {
2+
req.respond('foobar')
3+
}

test/fixtures/app_hooks/_hook.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export ->(req, app) {
2+
(req.ctx[:hooks] ||= []) << :root
3+
app.(req)
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export ->(req, app) {
2+
(req.ctx[:hooks] ||= []) << :foo
3+
app.(req)
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export ->(req, app) {
2+
(req.ctx[:hooks] ||= []) << :bar
3+
app.(req)
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export ->(req, app) {
2+
(req.ctx[:hooks] ||= []) << :baz
3+
app.(req)
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export ->(req) {
2+
req.respond("baz: #{req.ctx[:hooks].join(' ')}")
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export ->(req) {
2+
req.respond("bar: #{req.ctx[:hooks].join(' ')}")
3+
}

0 commit comments

Comments
 (0)