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

Using relative path to cloud code file broken #1334

Closed
3 tasks done
airdrummingfool opened this issue Apr 2, 2016 · 1 comment
Closed
3 tasks done

Using relative path to cloud code file broken #1334

airdrummingfool opened this issue Apr 2, 2016 · 1 comment

Comments

@airdrummingfool
Copy link
Contributor

Steps to reproduce

I've seen conflicting information regarding whether or not using a relative path to the cloud code is allowed:

var api = new ParseServer({
  cloud: './cloud/main.js',
  ...
});

The info that states it is supported:

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.

@flovilmart
Copy link
Contributor

In that case, we should use something like:

require(path.resolve(process.cwd(), cloudCodePath)

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

2 participants