Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
Add comments to explain the example's proxy use.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick committed Apr 28, 2015
1 parent 115b90d commit afdb8e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-isomorphic-starterkit",
"description": "Isomorphic starterkit with server-side React rendering.",
"version": "2.3.2",
"version": "2.3.3",
"license": "BSD-3",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ server.route({
});

/**
* Endpoint that proxies all requests to api.github.com
* Endpoint that proxies all GitHub API requests to https://api.github.com.
*/
server.route({
method: "*",
path: "/api/github/{path*}",
handler: {
proxy: {
passThrough: true,
mapUri: function (request, callback) {
mapUri (request, callback) {
callback(null, url.format({
protocol: "https",
host: "api.github.com",
Expand Down
9 changes: 9 additions & 0 deletions src/views/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,22 @@ export default Transmit.createContainer(Main, {
* Return a Promise of the previous stargazers + the newly fetched stargazers.
*/
allStargazers (queryParams) {
/**
* On the server, connect to GitHub directly.
*/
let githubApi = "https://api.github.com";

/**
* On the client, connect to GitHub via the Hapi proxy route.
*/
if (__CLIENT__) {
const {hostname, port} = window.location;
githubApi = `http://${hostname}:${port}/api/github`;
}

/**
* Load a few stargazers using the Fetch API.
*/
return fetch(
githubApi + "/repos/RickWong/react-isomorphic-starterkit/stargazers" +
`?per_page=100&page=${queryParams.nextPage}`
Expand Down

0 comments on commit afdb8e5

Please sign in to comment.