-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to refresh data on the development server
The external source data can be refreshed by making a POST request to the `__refresh` endpoint. If the env var GATSBY_REFRESH_TOKEN is present there needs to be a matching `Authorization` header. This post request is wrapped for convenience with the command `gatsby refresh` which uses localhost:8000 by default, but allows for a host and port to be specified in the same way as `gatsby develop`.
- Loading branch information
Justin Schulz
committed
Dec 4, 2017
1 parent
e6924c4
commit 64c6d2a
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* @flow */ | ||
|
||
const http = require(`http`) | ||
|
||
module.exports = async (program: { host: string, port: string }) => { | ||
const options = { | ||
host: program.host, | ||
port: program.port, | ||
path: `/__refresh`, | ||
method: `POST`, | ||
} | ||
|
||
const req = http.request(options, (res) => { | ||
res.on(`end`, () => { | ||
console.log() | ||
console.info(`Successfully refreshed external data`) | ||
}) | ||
}) | ||
|
||
req.on(`error`, (e) => { | ||
console.log() | ||
console.error(`Unable to refresh external data: ${e.message}`) | ||
}) | ||
|
||
req.end() | ||
} |