Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash the app if does not find index.html, index.js or favico.ico #653

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function resolveApp(relativePath) {
module.exports = {
appBuild: resolveApp('build'),
appHtml: resolveApp('index.html'),
appIndexJs: resolveApp('src/index.js'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Let’s use this variable instead of path.join(paths.appSrc, 'index') in webpack.config.dev and .prod too.

appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
testsSetup: resolveApp('src/setupTests.js'),
Expand All @@ -52,6 +53,7 @@ function resolveOwn(relativePath) {
module.exports = {
appBuild: resolveApp('build'),
appHtml: resolveApp('index.html'),
appIndexJs: resolveApp('src/index.js'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
testsSetup: resolveApp('src/setupTests.js'),
Expand All @@ -66,6 +68,7 @@ module.exports = {
module.exports = {
appBuild: resolveOwn('../build'),
appHtml: resolveOwn('../template/index.html'),
appIndexJs: resolveOwn('../template/src/index.js'),
appPackageJson: resolveOwn('../package.json'),
appSrc: resolveOwn('../template/src'),
testsSetup: resolveOwn('../template/src/setupTests.js'),
Expand Down
2 changes: 1 addition & 1 deletion config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = {
// We ship a few polyfills by default.
require.resolve('./polyfills'),
// Finally, this is your app's code:
path.join(paths.appSrc, 'index')
paths.appIndexJs
// We include the app code last so that if there is a runtime error during
// initialization, it doesn't blow up the WebpackDevServer client, and
// changing JS code would still trigger a refresh.
Expand Down
2 changes: 1 addition & 1 deletion config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
// In production, we only want to load the polyfills and the app code.
entry: [
require.resolve('./polyfills'),
path.join(paths.appSrc, 'index')
paths.appIndexJs
],
output: {
// The build folder.
Expand Down
20 changes: 18 additions & 2 deletions scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

process.env.NODE_ENV = 'development';

var fs = require('fs');
var path = require('path');
var chalk = require('chalk');
var webpack = require('webpack');
Expand Down Expand Up @@ -170,6 +171,20 @@ function openBrowser(port, protocol) {
opn(protocol + '://localhost:' + port + '/');
}

function checkRequiredFiles() {
var filesPathToCheck = [paths.appHtml, paths.appIndexJs];
filesPathToCheck.forEach(function(filePath) {
try {
fs.accessSync(filePath, fs.F_OK);
} catch (err) {
var fileName = path.basename(filePath);
console.log(
chalk.red(`Cannot find ${fileName} in ${filePath} directory`)
);
process.exit(1);
}
});
}
// We need to provide a custom onError function for httpProxyMiddleware.
// It allows us to log custom error messages on the console.
function onProxyError(proxy) {
Expand All @@ -180,7 +195,7 @@ function onProxyError(proxy) {
' from ' + chalk.cyan(host) + ' to ' + chalk.cyan(proxy) + '.'
);
console.log(
'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
chalk.cyan(err.code) + ').'
);
console.log();
Expand All @@ -190,7 +205,7 @@ function onProxyError(proxy) {
if (res.writeHead && !res.headersSent) {
res.writeHead(500);
}
res.end('Proxy error: Could not proxy request ' + req.url + ' from ' +
res.end('Proxy error: Could not proxy request ' + req.url + ' from ' +
host + ' to ' + proxy + ' (' + err.code + ').'
);
}
Expand Down Expand Up @@ -304,6 +319,7 @@ function runDevServer(port, protocol) {

function run(port) {
var protocol = process.env.HTTPS === 'true' ? "https" : "http";
checkRequiredFiles();
setupCompiler(port, protocol);
runDevServer(port, protocol);
}
Expand Down