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

Add endpoint for refresh #3293

Merged
merged 1 commit into from
Dec 20, 2017
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
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