How to route URL's with koa-router

464 Views Asked by At

I am trying to route a URL which I am calling fetch on to a function using koa-router. The URL ends with /email/[email protected], and is supposed to fetch a user object by their email. The router object defines:

router.get( uri_prefix+'/email/:email', readUserByEmail);

The definition of the function is as follows:

async function readUserByEmail (ctx, next) {
  try {
    // get params
    let _EMAIL = ctx.params.email;
    ...
}

I know that the router works for other functions (such as get user by id), however, it doesn't seem to invoke the function readUserByEmail.

I am not sure what the problem is - whether I am not defining the route correctly, or the function (in terms of parameters), or maybe there are other files I should edit, or maybe something else.

Any help or tips would be appreciated

1

There are 1 best solutions below

0
On

The problem in my case was:

The changes that I was making to the routes were correct, but they were all local (while the actual app was configured to interact with the server that is online), therefore it didn't work.

It is worth looking at where the changes you made run and where the application itself runs.