JKHeadley / rest-hapi

🚀 A RESTful API generator for Node.js
https://resthapi.com
MIT License
1.19k stars 153 forks source link

config.enablePolicies = true dose not work on windows #231

Closed yoieh closed 4 years ago

yoieh commented 4 years ago

Describe the bug When setting config.enablePolicies = true the policyDirectory is set to the root dir of the project and every file in the project gets loaded as a policy and fails.

To Reproduce Steps to reproduce the behavior:

  1. on windows spread rest-hapi in to your config and enable enablePolicies
    
    ...
    const RestHapi = require("rest-hapi");

cosnt config = { ...RestHapi.config, enablePolicies: true } ...

2. add console.log in side of mrhorse lib folder

node_modules\mrhorse\lib\index.js:179 ... 197: console.log(policyName, policy) ...

3. run `npm start`
4. See error

.... auditLogTTL null Error starting server: TypeError: Cannot read property 'applyPoint' of null at hasValidApplyPoint ([...]\node_modules\mrhorse\lib\index.js:18:20) at addPolicy ([...]\node_modules\mrhorse\lib\index.js:184:10) at [...]\node_modules\mrhorse\lib\index.js:226:64 at [...]\node_modules\lodash\lodash.js:4905:15 at baseForOwn ([...]\node_modules\lodash\lodash.js:2990:24) at [...]\node_modules\lodash\lodash.js:4874:18 at Function.forEach ([...]\node_modules\lodash\lodash.js:9342:14) at loadPolicyFile ([...]\node_modules\mrhorse\lib\index.js:226:23) at loadPolicies ([...]\node_modules\mrhorse\lib\index.js:240:9) at Object.register ([...]\node_modules\mrhorse\lib\index.js:288:15) at internals.Server.register ([...]\node_modules\@hapi\hapi\lib\server.js:466:35) at registerMrHorse ([...]\node_modules\rest-hapi\rest-hapi.js:215:16) at Object.register ([...]\node_modules\rest-hapi\rest-hapi.js:115:9) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async internals.Server.register ([...]\node_modules\@hapi\hapi\lib\server.js:466:17) at async api ([...]\api.js:25:5)



**Expected behavior**
It should not crash and load my policies

**Desktop (please complete the following information):**
 - OS: win 10
 - Version: 2.0 but hade the same problem in 1.9.x
 - Nodejs: v12.16.1