Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// to enable using sub routes in our controller we create
// a new router. This router is a ChildRouter and will delegate
// all error and 404 handler to it's parent. i.e. the global
// application
var controller = Router({ prefix: prefix })
// We instantiate our model here with the database configuration
// the model is local to this user feature
var model = UserModel(config.db)
// we set up configuration to pass to our views.
// we also set up an urlMap so that views are not hard coded
// to specific paths
var viewsConfig = { layout: config.layout, urlMap: {
"user": format.bind(null, prefix + "/{userId}"),
"userEdit": format.bind(null, prefix + "/{userId}/edit"),
"userPet": format.bind(null, prefix + "/{userId}/pet"),
"pet": format.bind(null, config.features.pet + "/{petId}")
} }
// optionally /. so its /user & /user/
controller.addRoute("/?", function (req, res, opts, cb) {
model.getAll(function (err, users) {
if (err) {
return cb(err)
}
sendHtml(req, res, usersPage(users, viewsConfig))
})
})
// to enable using sub routes in our controller we create
// a new router. This router is a ChildRouter and will delegate
// all error and 404 handler to it's parent. i.e. the global
// application
var controller = Router({ prefix: prefix })
// We instantiate our model here with the database configuration
// the model is local to this user feature
var model = UserModel(config.db)
// we set up configuration to pass to our views.
// we also set up an urlMap so that views are not hard coded
// to specific paths
var viewsConfig = { layout: config.layout, urlMap: {
"user": format.bind(null, prefix + "/{userId}"),
"userEdit": format.bind(null, prefix + "/{userId}/edit"),
"userPet": format.bind(null, prefix + "/{userId}/pet"),
"pet": format.bind(null, config.features.pet + "/{petId}")
} }
// optionally /. so its /user & /user/
controller.addRoute("/?", function (req, res, opts, cb) {
model.getAll(function (err, users) {
if (err) {
return cb(err)
}
sendHtml(req, res, usersPage(users, viewsConfig))
})
})
controller.addRoute("/:userId/edit", function (req, res, opts, cb) {
// a new router. This router is a ChildRouter and will delegate
// all error and 404 handler to it's parent. i.e. the global
// application
var controller = Router({ prefix: prefix })
// We instantiate our model here with the database configuration
// the model is local to this user feature
var model = UserModel(config.db)
// we set up configuration to pass to our views.
// we also set up an urlMap so that views are not hard coded
// to specific paths
var viewsConfig = { layout: config.layout, urlMap: {
"user": format.bind(null, prefix + "/{userId}"),
"userEdit": format.bind(null, prefix + "/{userId}/edit"),
"userPet": format.bind(null, prefix + "/{userId}/pet"),
"pet": format.bind(null, config.features.pet + "/{petId}")
} }
// optionally /. so its /user & /user/
controller.addRoute("/?", function (req, res, opts, cb) {
model.getAll(function (err, users) {
if (err) {
return cb(err)
}
sendHtml(req, res, usersPage(users, viewsConfig))
})
})
controller.addRoute("/:userId/edit", function (req, res, opts, cb) {
model.get(opts.userId, function (err, user) {
// all error and 404 handler to it's parent. i.e. the global
// application
var controller = Router({ prefix: prefix })
// We instantiate our model here with the database configuration
// the model is local to this user feature
var model = UserModel(config.db)
// we set up configuration to pass to our views.
// we also set up an urlMap so that views are not hard coded
// to specific paths
var viewsConfig = { layout: config.layout, urlMap: {
"user": format.bind(null, prefix + "/{userId}"),
"userEdit": format.bind(null, prefix + "/{userId}/edit"),
"userPet": format.bind(null, prefix + "/{userId}/pet"),
"pet": format.bind(null, config.features.pet + "/{petId}")
} }
// optionally /. so its /user & /user/
controller.addRoute("/?", function (req, res, opts, cb) {
model.getAll(function (err, users) {
if (err) {
return cb(err)
}
sendHtml(req, res, usersPage(users, viewsConfig))
})
})
controller.addRoute("/:userId/edit", function (req, res, opts, cb) {
model.get(opts.userId, function (err, user) {
if (err) {