Skip to content

Commit

Permalink
Handle absolute paths in REACT_SERVER_CONFIGS (#901)
Browse files Browse the repository at this point in the history
Looks like #871 introduced a regression where absolute paths are no longer
supported in the `REACT_SERVER_CONFIGS` environment variable.

This can be addressed by using `path.resolve`:
```js
> path.resolve("/home/foo", "bar/baz", "config");
'/home/foo/bar/baz/config'
> path.resolve("/home/foo", "/bar/baz", "config");
'/bar/baz/config'
```

In place of `path.join`:
```js
> path.join("/home/foo", "bar/baz", "config");
'/home/foo/bar/baz/config'
> path.join("/home/foo", "/bar/baz", "config");
'/home/foo/bar/baz/config'
```

I also removed the path concatenation (`... + "/config"`).
  • Loading branch information
gigabo authored Mar 21, 2017
1 parent a61ef93 commit 0381911
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/react-server/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ if (SERVER_SIDE) {

// Node.js tries to load `config.js` file first. If `config.js` doesn't exist, Node.js
// then try to load `config.json`.
configFilePath = path.join(process.cwd(), configFilePath + "/config");
//
// If `configFilePath` is absolute `require.resolve` will
// reset to it, correctly overriding `process.cwd()`. If it
// is relative, then it will be relative to `process.cwd()`.
//
configFilePath = path.resolve(process.cwd(), configFilePath, "config");
config = Object.freeze(require(configFilePath));
} else {
config = Object.freeze({});
Expand Down

0 comments on commit 0381911

Please sign in to comment.