Skip to content

Commit

Permalink
feat(gatsby): improve refresh endpoint output (#28621) (#28641)
Browse files Browse the repository at this point in the history
* feat(gatsby): improve refresh endpoint output

* update status-codes

* add error msg

(cherry picked from commit deb4e1e)

Co-authored-by: Ward Peeters <ward@coding-tech.com>
  • Loading branch information
LekoArts and wardpeet authored Dec 15, 2020
1 parent 9cd252f commit 2e7250e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/gatsby/src/utils/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ module.exports = {

if (enableRefresh && authorizedRefresh) {
refresh(req, pluginName)
res.status(200)
res.setHeader(`content-type`, `application/json`)
} else {
res.status(authorizedRefresh ? 404 : 403)
res.json({
error: enableRefresh
? `Authorization failed. Make sure you add authorization header to your refresh requests`
: `Refresh endpoint is not enabled. Run gatsby with "ENABLE_GATSBY_REFRESH_ENDPOINT=true" environment variable set.`,
isEnabled: !!process.env.ENABLE_GATSBY_REFRESH_ENDPOINT,
})
}
res.end()
})
Expand Down Expand Up @@ -461,6 +471,12 @@ module.exports = {
}

app.use(async (req, res) => {
// in this catch-all block we don't support POST so we should 404
if (req.method === `POST`) {
res.status(404).end()
return
}

const fullUrl = req.protocol + `://` + req.get(`host`) + req.originalUrl
// This isn't used in development.
if (fullUrl.endsWith(`app-data.json`)) {
Expand Down

0 comments on commit 2e7250e

Please sign in to comment.