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

[v2] Properly serve static files #7952

Merged
merged 1 commit into from
Sep 8, 2018
Merged
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
29 changes: 1 addition & 28 deletions packages/gatsby/src/commands/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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)
Expand Down