Route from group doesn't match because lacks of domain #4842
Unanswered
alexandercerutti
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I was developing a set of plugins for Adonis in order to automatically integrate a predefined set of routes. Such plugins are made in order to specify only a few handling methods and nothings else.
The only way I found to create a plugin is by making something like this:
Then to be sure that everything works as expected, I'm testing through
node ace test
both importing the plugins (ESM) and HTTP Request.To test the requests, I'm using (as suggested) the
apiClient
adonis plugin from Japa.And then in the test, after the
router.group(...)
, I make the request:While running
node ace test
the routes do not match even if they are strictly equal.So I started debugging both
ace
process and the subprocess it creates fortest
.I reached this part of code, where the route is attempted to be matched:
https://github.com/adonisjs/http-server/blob/474ec192aed1730e572493cccce5a4904c419394/src/server/factories/final_handler.ts#L17-L34
When
router.match()
is invoked, this happens:https://github.com/adonisjs/http-server/blob/06a28eed841ec64263249a8373cca017f7e6720d/src/router/main.ts#L375-L384
I didn't specify any domain, so the ternary check fails and goes to check
.match
without the third parameter. It fails here:https://github.com/adonisjs/http-server/blob/06a28eed841ec64263249a8373cca017f7e6720d/src/router/store.ts#L186-L205
So basically, it seems to not be able to find the root domain. When I build the sample application and add the routes, I can make them work perfectly. They answer as expected from another device. The usage is the same.
I'm not exactly getting why it is failing, but
root
doesn't exists underthis.tree
. Checking the chain of wherethis.tree.domains
gets populated, brings me to theRouteStore.prototype.add
method, which seems to get never added.So, I'm not understanding if such method is supposed to get called or not or what is going on.
Doesn't anyone know how to solve this?
Is this the supposed way to create third party routes plugins for Adonis? I would get so, as the groups seems to be working fine outside the tests. If not, can you please point to where I can find a better way?
Thank you.
UPDATE 1: I kept digging down. I see that at a certain point (with routes preloading),
.add
is invoked for the routes inssrc/start/routes.ts
. However, whenrouter.group
is invoked inside a test, this doesn't.It feels like this is too late to add a route...
UPDATE 2:
The "problem" seems the commiting phase of
@adonisjs/http-server
.And if I'm right, the server is shared between different tests... so a route cannot even get atomically added several times, with different things (handlers, in my case).
And if this is confirmed, I guess the way to make functional tests like this, is going for the hard way and setup Adonis manually somehow, maybe without the Ignitor? Not even sure this is a viable way, as I'd need to create a new application for every test or something like that...
Beta Was this translation helpful? Give feedback.
All reactions