diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index ba6ec3aab..0702a5dd8 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -445,7 +445,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "nc -w 5 -z localhost 8081 > /dev/null 2>&1 || open $SRCROOT/../packager/launchPackager.command || echo \"Can't start packager automatically\""; + shellScript = "if nc -w 5 -z localhost 8081 ; then\n if ! curl -s \"http://localhost:8081/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port 8081 already in use, packager is either not running or not running correctly\"\n exit 2\n fi\nelse\n open $SRCROOT/../packager/launchPackager.command || echo \"Can't start packager automatically\"\nfi"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/packager/packager.js b/packager/packager.js index 9503df6ea..ad47d1d99 100644 --- a/packager/packager.js +++ b/packager/packager.js @@ -150,6 +150,17 @@ function getDevToolsLauncher(options) { }; } +// A status page so the React/project.pbxproj build script +// can verify that packager is running on 8081 and not +// another program / service. +function statusPageMiddleware(req, res, next) { + if (req.url === '/status') { + res.end('packager-status:running'); + } else { + next(); + } +} + function getAppMiddleware(options) { return ReactPackager.middleware({ projectRoots: options.projectRoots, @@ -168,6 +179,7 @@ function runServer( .use(loadRawBody) .use(openStackFrameInEditor) .use(getDevToolsLauncher(options)) + .use(statusPageMiddleware) .use(getAppMiddleware(options)); options.projectRoots.forEach(function(root) {