From 19137c9a9245eb6da3bdd8465ee8887b9f362b6e Mon Sep 17 00:00:00 2001 From: Yurick Date: Fri, 7 Sep 2018 03:30:27 -0300 Subject: [PATCH] Properly use express' static middleware --- packages/gatsby/src/commands/develop.js | 29 +------------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/packages/gatsby/src/commands/develop.js b/packages/gatsby/src/commands/develop.js index 2a2d7613ae635..e71bb560b8c4b 100644 --- a/packages/gatsby/src/commands/develop.js +++ b/packages/gatsby/src/commands/develop.js @@ -131,7 +131,7 @@ async function startServer(program) { res.end() }) - app.use(express.static(__dirname + `/public`)) + app.use(express.static(`public`)) app.use( require(`webpack-dev-middleware`)(compiler, { @@ -158,33 +158,6 @@ async function startServer(program) { }) } - // Check if the file exists in the public folder. - app.get(`*`, (req, res, next) => { - // Load file but ignore errors. - res.sendFile( - directoryPath(`/public${decodeURIComponent(req.path)}`), - err => { - // No err so a file was sent successfully. - if (!err || !err.path) { - next() - } else if (err) { - // There was an error. Let's check if the error was because it - // couldn't find an HTML file. We ignore these as we want to serve - // all HTML from our single empty SSR html file. - const parsedPath = parsePath(err.path) - if ( - parsedPath.extname === `` || - parsedPath.extname.startsWith(`.html`) - ) { - next() - } else { - res.status(404).end() - } - } - } - ) - }) - // Render an HTML page and serve it. app.use((req, res, next) => { const parsedPath = parsePath(req.path)