Skip to content

Using relative path to cloud code file broken #1334

Closed
@airdrummingfool

Description

@airdrummingfool

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions