Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-GET requests logging errors #21

Open
smohamali opened this issue Sep 14, 2016 · 2 comments
Open

Non-GET requests logging errors #21

smohamali opened this issue Sep 14, 2016 · 2 comments

Comments

@smohamali
Copy link

smohamali commented Sep 14, 2016

I have an un-usual situation where all non-get requests against models are returning 500 internal server error.

The error in the log is:

error: undefined error: Unknown keystone list "api" error: ReferenceError: Unknown keystone list "api" at list (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\lib\core\list.js:12:18) at C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\lib\core\routes.js:55:24 at Layer.handle [as handle_request] (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\layer.js:95:5) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:131:13) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) at next (C:\dev\workspace\oeh-assmt-mgmt\node_modules\keystone\node_modules\express\lib\router\route.js:125:14) POST /keystone/api/assessments 500 97.558 ms

Some snippets from how I configured restful keystone:

restful.expose({ Assessment: { methods: true } })

I also have a couple of keystone "pre" middleware configured for the purposes of token verification and logging.

Some keystone config:

`{

'name': 'oeh-assmt-mgmt',

'favicon': 'public/favicon.ico',
'less': 'public',
'static': ['public'],

'views': 'templates/views',
'view engine': 'jade',

'auto update': true,
'mongo': 'mongodb://localhost:27017/oeh-assmt-mgmt',

'session': false,
'auth': false,
'cookie secret': '(your secret here)'

}`

The GET request works fine:

GET /keystone/api/assessments

{ "results": [ { "id": "57d90b0dd55cf37c28e7d56b", "name": "57d90b0dd55cf37c28e7d56b", "fields": { "caseid": "1", "version": "1", "organisation": "envirokey", "blob": "{\"sdfsdf\": \"sdfsdfsdf\", \"32432\": true}" } } ], "count": 1 }

The POST request doesnt:

POST /keystone/api/assessments

@smohamali
Copy link
Author

smohamali commented Sep 16, 2016

Some other observations, the same code works fine in a linux environment (ubuntu or redhat), but it fails in the way illustrated above in windows.

Curiously I get some msbuild errors when npm install is executed. The error states that visual studio c++ 2010 tools could not be found. I have visual studio c++ 2015 tools installed.

`> [email protected] install C:\dev\workspace\oeh-assmt-mgmt\node_modules\ursa

node-gyp rebuild

C:\dev\workspace\oeh-assmt-mgmt\node_modules\ursa>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(55,5): error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build u
sing the v100 build tools, please install Visual Studio 2010 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, an
d then selecting "Retarget solution". [C:\dev\workspace\oeh-assmt-mgmt\node_modules\ursa\build\ursaNative.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:276:23)
gyp ERR! stack at emitTwo (events.js:106:13)
gyp ERR! stack at ChildProcess.emit (events.js:191:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Windows_NT 10.0.14393
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\dev\workspace\oeh-assmt-mgmt\node_modules\ursa
gyp ERR! node -v v6.5.0
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok
npm WARN install:[email protected] [email protected] install: node-gyp rebuild
npm WARN install:[email protected] Exit status 1`

@smohamali
Copy link
Author

smohamali commented Sep 19, 2016

Ok, found the root cause of the issue.

On windows, the methods are exposed with incorrect paths, as shown in a print-out of the app._router.stack object:

Layer {
handle: [Function: bound dispatch],
name: 'bound dispatch',
params: undefined,
path: undefined,
keys: [ [Object] ],
regexp: /^\api\users/(?:([^\/]+?))/?$/i,
route: Route { path: '\api\users/:id', stack: [Object], methods: [Object] } } ]

Note the use of backslashes in the regexp and Route objects.

I ran the process with the debugger enabled and manually overrode the generated paths in exposeList.js / exposeLists function such that that paths utilise forward slashes and this resolved the issue!

The issue appears to be in the use of the path object on line 14 in exposeLists.js. The API indicates that this method joins strings together using the platform specific separate which in the case of Windows is a backslash ().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant