Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

JS: Fix undefined file reference when invoked from another directory #84

Merged
merged 1 commit into from
Oct 9, 2015

Conversation

robatron
Copy link
Contributor

@robatron robatron commented Oct 9, 2015

Fixes an undefined-file error when attempting to access the API when JavaScript server is started from a directory other than the project root directory, e.g.,

$ PORT=3001 node node_modules/react-tutorial/server.js

Server started: http://localhost:3001/
undefined:1
undefined
^

SyntaxError: Unexpected token u
    at Object.parse (native)
    at ReadFileContext.callback (/Users/rob/code/react-tutorial-official/server.js:28:19)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:303:13)

This change makes the comments.json file reference relative to the server.js script.

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@@ -16,6 +16,8 @@ var express = require('express');
var bodyParser = require('body-parser');
var app = express();

var COMMENTS_FILE = path.join(__dirname, 'comments.json');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matches the script-relative path pattern used to reference the project's 'public' directory on line 23.

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@zpao
Copy link
Member

zpao commented Oct 9, 2015

Awesome, thanks!

zpao added a commit that referenced this pull request Oct 9, 2015
JS: Fix undefined file reference when invoked from another directory
@zpao zpao merged commit 4b3b2a0 into reactjs:master Oct 9, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants