You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using relative path to cloud code file broken #1334
Places that indicate that absolute path is necessary:
#1183: You shoud use absolute path for your cloud code.
README.md: cloud: '/home/myApp/cloud/main.js', // Absolute path to your Cloud Code
The issue is that using ./cloud/main.js as the cloud code path actually loads [root]/node_modules/parse-server/lib/cloud/main.js, instead of the expected [root]/cloud/main.js, and it does so silently (since the require() call is successful). Once the wrong main.js file is loaded, any call to cloud code results in Error: Invalid function. (which is hard to debug).
It would be great if using ./cloud/main.js worked as expected. In my case, I'm loading my parse config from config files, so I cannot (easily) do __dirname + '/cloud/main.js'. It also seems cleaner to be able to reference the file relatively (and it makes the code that much more portable).
In some informal testing, it appears that modifying ParseServer.js to do a simple path.resolve(cloud) in the require() at line 212 allows my main.js file to be loaded correctly. I'm not familiar enough with Parse Server (or even Node.js) to suggest that as a competent solution without someone else's sanity check, but I ran the tests and they all passed (although there doesn't appear to be much testing around loading cloud code files). If someone can gut-check this solution (or propose a better one) I'd be happy to submit a PR.
If the consensus is instead that using a relative path is off the table, I can provide a PR to fix the comment, but someone else will have to fix the wiki example.
Activity
flovilmart commentedon Apr 2, 2016
In that case, we should use something like:
Fixes parse-community#1334 by resolving relative cloud code file path…
Fix for #1334: using relative cloud code files broken