strongloop / loopback-component-storage

Storage component for LoopBack.
Other
130 stars 155 forks source link

Issue with relative path for root when running from non-project directory #251

Closed ketansp closed 5 years ago

ketansp commented 6 years ago

Description/Steps to reproduce

To give you some context, my datasources.json file currently looks like this.

"localServerStorage": {
    "name": "localServerStorage",
    "connector": "loopback-component-storage",
    "provider": "filesystem",
    "root": "uploads",
    "nameConflict": "makeUnique"
  }

Here, I am specifying root as a relative path from the project directory. The expected behaviour is to have uploads directory inside my project directory. When I run the project using node . or node server/server.js command (from project directory), the connector works absolutely fine.

However when I navigate to any directory other than the project and try to start loopback server using node path/to/my/project/server/server.js, the connector starts looking for the root path in the current working directory, not actual project directory, thus giving Path does not exist exception.

Expected result

One should be able to run loopback project from any directory, not just project directory.

Additional information

The root cause is that fs.existsSync function checks if a file/directory exists by attaching the relative path to present working directory, not to the main script

ketansp commented 6 years ago

Raised PR #252

dhmlau commented 6 years ago

@jannyHou , i'm assigning this to you since you're helping with the PR already. Thanks.

dhmlau commented 5 years ago

It's resolved in PR #279. Closing this issue. Thanks.