Skip to content

Commit

Permalink
Add endpoint for refresh
Browse files Browse the repository at this point in the history
This is only active if you actively enable via an environment variable.
  • Loading branch information
Justin Schulz committed Dec 20, 2017
1 parent 1354671 commit 28da65b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/gatsby/src/commands/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const launchEditor = require(`react-dev-utils/launchEditor`)
const formatWebpackMessages = require(`react-dev-utils/formatWebpackMessages`)
const chalk = require(`chalk`)
const address = require(`address`)
const sourceNodes = require(`../utils/source-nodes`)

// const isInteractive = process.stdout.isTTY

Expand Down Expand Up @@ -91,6 +92,24 @@ async function startServer(program) {
graphiql: true,
})
)

/**
* Refresh external data sources.
* This behavior is disabled by default, but the ENABLE_REFRESH_ENDPOINT env var enables it
* If no GATSBY_REFRESH_TOKEN env var is available, then no Authorization header is required
**/
app.post(`/__refresh`, (req, res) => {
const enableRefresh = process.env.ENABLE_GATSBY_REFRESH_ENDPOINT
const refreshToken = process.env.GATSBY_REFRESH_TOKEN
const authorizedRefresh = (!refreshToken || req.headers.authorization === refreshToken)

if (enableRefresh && authorizedRefresh) {
console.log(`Refreshing source data`)
sourceNodes()
}
res.end()
})

app.get(`/__open-stack-frame-in-editor`, (req, res) => {
launchEditor(req.query.fileName, req.query.lineNumber)
res.end()
Expand Down

0 comments on commit 28da65b

Please sign in to comment.