modofunjs / modofun

A fast function router for serverless Node.js applications
https://modofun.js.org
MIT License
95 stars 4 forks source link

How to split routes into multiple paths and subpaths? #7

Open tstibbs opened 3 years ago

tstibbs commented 3 years ago

My routes currently look something like this:

{
    'abcLogin': handleAbcLogin,
    'abcLogout': handleAbcVerify,
    'abcDoAction': handleAbcDoAction,
    'xyzLogin': handleXyzLogin,
    'xyzLogout': handleXyzVerify,
    'xyzDoAction': handleXyzDoAction
}

but I'd like the paths to look like this:

{
    'abc/Login': handleAbcLogin,
    'abc/Logout': handleAbcVerify,
    'abc/DoAction': handleAbcDoAction,
    'xyz/Login': handleXyzLogin,
    'xyz/Logout': handleXyzVerify,
    'xyz/DoAction': handleXyzDoAction
}

Adding a slash into the path doesn't appear to work. I also considered trying to created multiple modofun routers so I could have a master router with just routes for abc and xyz and then have 'sub' routers for each of the three routes within abc and xyz. However, afaics that's not going to work because modofun expects the incoming thing to look like a request from AWS etc.

Is there any other way of achieving this?

(this is a really useful library btw, I've used it in loads of serverless projects over the years, thank you!)