trailsjs / trails

:evergreen_tree: Modern Web Application Framework for Node.js.
http://trailsjs.io
Other
1.66k stars 70 forks source link

Error adding policy to routes config #300

Closed clayrisser closed 7 years ago

clayrisser commented 7 years ago

Issue Description

When I add a policy to the routes config it throws the following error. Config

config: {
  pre: [
    'ReportPolicy.isEvil'
  ]
}

Error

error: 
 TypeError: argument handler must be a function
    at Route.(anonymous function) [as get] (/home/jamrizzi/Projects/trailblazer/node_modules/router/lib/route.js:213:15)
    at Function.Router.(anonymous function) [as get] (/home/jamrizzi/Projects/trailblazer/node_modules/router/index.js:533:19)
    at Function.app.(anonymous function) [as get] (/home/jamrizzi/Projects/trailblazer/node_modules/trailpack-express/lib/utils.js:24:31)
    at _.each (/home/jamrizzi/Projects/trailblazer/node_modules/trailpack-express/lib/server.js:298:26)
    at /home/jamrizzi/Projects/trailblazer/node_modules/lodash/lodash.js:4944:15
    at baseForOwn (/home/jamrizzi/Projects/trailblazer/node_modules/lodash/lodash.js:3001:24)
    at /home/jamrizzi/Projects/trailblazer/node_modules/lodash/lodash.js:4913:18
    at Function.forEach (/home/jamrizzi/Projects/trailblazer/node_modules/lodash/lodash.js:9359:14)
    at Object.registerRoutes (/home/jamrizzi/Projects/trailblazer/node_modules/trailpack-express/lib/server.js:242:7)
    at Object.registerMiddlewares (/home/jamrizzi/Projects/trailblazer/node_modules/trailpack-express/lib/server.js:115:14)
    at Express.initialize (/home/jamrizzi/Projects/trailblazer/node_modules/trailpack-express/index.js:49:18)
    at app.after.then.then (/home/jamrizzi/Projects/trailblazer/node_modules/trails/lib/trailpack.js:42:26)
error: The application did not boot successfully.
error: Try increasing the loglevel to "debug" to learn more
info: Shutting down...
TypeError: Cannot read property 'db' of undefined
    at Object.teardown (/home/jamrizzi/Projects/trailblazer/node_modules/sails-mongo/lib/adapter.js:166:54)
    at /home/jamrizzi/Projects/trailblazer/node_modules/waterline/lib/waterline.js:232:25
    at /home/jamrizzi/Projects/trailblazer/node_modules/async/lib/async.js:181:20
    at Object.async.forEachOf.async.eachOf (/home/jamrizzi/Projects/trailblazer/node_modules/async/lib/async.js:233:13)
    at Object.async.forEach.async.each (/home/jamrizzi/Projects/trailblazer/node_modules/async/lib/async.js:209:22)
    at module.exports.teardown (/home/jamrizzi/Projects/trailblazer/node_modules/waterline/lib/waterline.js:226:9)
    at Promise (/home/jamrizzi/Projects/trailblazer/node_modules/trailpack-waterline/index.js:66:15)
    at WaterlineTrailpack.unload (/home/jamrizzi/Projects/trailblazer/node_modules/trailpack-waterline/index.js:65:12)
    at Promise.all.loadedPacks.map.pack (/home/jamrizzi/Projects/trailblazer/node_modules/trails/index.js:199:21)
    at Array.map (native)
    at TrailsApp.stop (/home/jamrizzi/Projects/trailblazer/node_modules/trails/index.js:197:24)
    at app.after.then.then.catch.err (/home/jamrizzi/Projects/trailblazer/node_modules/trails/lib/trailpack.js:43:27)

Environment

{"app":"0.0.0","node":"v7.10.1","libs":{"http_parser":"2.7.0","node":"7.10.1","v8":"5.5.372.43","uv":"1.11.0","zlib":"1.2.11","ares":"1.10.1-DEV","modules":"51","openssl":"1.0.2k","icu":"58.2","unicode":"9.0","cldr":"30.0.3","tz":"2016j"},"trailpacks":[{"name":"repl","version":"2.1.0"},{"name":"router","version":"2.1.0"},{"name":"express","version":"2.0.4"},{"name":"waterline","version":"2.0.0"},{"name":"footprints","version":"2.0.0"},{"name":"swagger","version":"2.0.5"}
clayrisser commented 7 years ago

I'm using Waterline with Mongo, and Express for the server

clayrisser commented 7 years ago

Ok, I figured it out. Policies are configured in the policies config file. This is not how you have it documented on the trailsjs website.

https://trailsjs.io/doc/en/build/policy

clayrisser commented 7 years ago

Proposed fix to the documentation

https://github.com/trailsjs/doc/pull/40

scott-wyatt commented 7 years ago

Closing this. The doc examples are currently written for Hapi and this is an Express issue. I will link to this issue with proposed changes to include Express documentation.

clayrisser commented 7 years ago

Ah, that makes sense. Where will the express documentation go?