При очередном запуске проекта выдает ошибку:
TypeError: registrationRules is not a function
at Object.<anonymous> (C:\Users\fenrir\Desktop\chat-app\chat-backend\router\auth.js:9:5)
at Module._compile (node:internal/modules/cjs/loader:1083:30)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
at Module.load (node:internal/modules/cjs/loader:948:32)
at Function.Module._load (node:internal/modules/cjs/loader:789:14)
at Module.require (node:internal/modules/cjs/loader:972:19)
at require (node:internal/modules/cjs/helpers:88:18)
at Object.<anonymous> (C:\Users\fenrir\Desktop\chat-app\chat-backend\router\index.js:7:17)
at Module._compile (node:internal/modules/cjs/loader:1083:30)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
Program node index.js exited with code 1
auth.js:
const router = require('express').Router()
const { login, register } = require('../controllers/authController')
const { validate } = require('../validators')
const { rules : registrationRules } = require('../validators/auth/register')
router.post('/login', login)
router.post('/register', [
registrationRules(),
validate
], register)
module.exports = router
register.js:
const {body} = require('express-validator')
exports.rules = () => {
return [
body('firstName').notEmpty(),
body('lastName').notEmpty(),
body('gender').notEmpty(),
body('email').isEmail(),
body('password').isLength({ min: 5})
]
}
Если передавать промежуточную функцию registrationRules без скобок, то выдает другую ошибку:
Error: Route.post() requires a callback function but got a [object Undefined]
at Route.<computed> [as post] (C:\Users\fenrir\Desktop\chat-app\chat-backend\node_modules\express\lib\router\route.js:211:15)
at Function.proto.<computed> [as post] (C:\Users\fenrir\Desktop\chat-app\chat-backend\node_modules\express\lib\router\index.js:521:19)
at Object.<anonymous> (C:\Users\fenrir\Desktop\chat-app\chat-backend\router\auth.js:8:8)
at Module._compile (node:internal/modules/cjs/loader:1083:30)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
at Module.load (node:internal/modules/cjs/loader:948:32)
at Function.Module._load (node:internal/modules/cjs/loader:789:14)
at Module.require (node:internal/modules/cjs/loader:972:19)
at require (node:internal/modules/cjs/helpers:88:18)
at Object.<anonymous> (C:\Users\fenrir\Desktop\chat-app\chat-backend\router\index.js:7:17)
Program node index.js exited with code 1