ukayani / restify-router

A router interface for restify that lets you aggregate route definitions and apply to a restify server
MIT License
52 stars 15 forks source link

Problem in combination with node-restify-validation npm module #21

Closed daniyel closed 5 years ago

daniyel commented 6 years ago

Hi.

I was using restify-router alone and then I have added node-restify-validation module and now I am getting errors. I am using nested routers with routes folder, v1 subfolder and auth.js route file.

The excerpt from auth.js file

router.post({ url: '/register', validation: {
    content: {
        name: { isRequired: true },
        email: { isRequired: true, isEmail: true },
        password: { isRequired: true }
    }
}}, function (req, res, next) {

Error:

TypeError: path must be string or RegExp
    at toRegex (/node_modules/restify-router/lib/path.js:19:9)
    at concat (/node_modules/restify-router/lib/path.js:59:16)
    at /node_modules/restify-router/lib/router.js:131:24
    at Array.forEach (<anonymous>)
    at /node_modules/restify-router/lib/router.js:127:27
    at Array.forEach (<anonymous>)
    at Router.applyRoutes (/node_modules/restify-router/lib/router.js:122:11)
    at /node_modules/restify-router/lib/router.js:144:12
    at Array.forEach (<anonymous>)
    at Router.applyRoutes (/node_modules/restify-router/lib/router.js:139:16)
    at /node_modules/restify-router/lib/router.js:144:12
    at Array.forEach (<anonymous>)
    at Router.applyRoutes (/node_modules/restify-router/lib/router.js:139:16)
    at NativeConnection.db.once (server.js:39:16)
    at Object.onceWrapper (events.js:273:13)
    at NativeConnection.emit (events.js:182:13)

I already did some console.log outputs and I am getting in the toRegex function in path.js

/v1/auth
undefined

I think the problem is it is not picking up the url property.

Best regards.

ukayani commented 6 years ago

Hi @daniyel,

This module is intended support the standard parameters supported by the restify module. When you supply an object as the param to .get, .post, etc it expects the path to be at the path property rather than the url property. For example,

router.post({ path: '/register' ... , (req, res, next) => {} )

The router uses the path property to figure out how to create the actual nested routing layer.

It seems that this library node-restify-validation does not use the standard path property but rather url instead.

I can take a look when i get some time if there is a way to support this without specifically knowing about node-restify-validation

ukayani commented 6 years ago

What happens if you use path instead of url? does that not work?

daniyel commented 5 years ago

Hi.

Yes later on I figured out if you put path instead of the url it does work, but I moved to other way of validating my request since I stumbled on another limitation, that plugin was not able to solve. So you might close this issue.

Thank you very much for putting some time into this matter.