Skip to content

Commit

Permalink
clean up getInitialProps across pages
Browse files Browse the repository at this point in the history
* Remove unused variables from the context object
* Document control flow differences for server vs client
  • Loading branch information
rgbkrk committed Sep 11, 2017
1 parent 4a045e7 commit 3da7c6f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/frontend/pages/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ const DiscoveryItem = props => (
);

class DiscoveryGrid extends React.Component<*> {
static async getInitialProps({ req, pathname, asPath, query }) {
static async getInitialProps({ req }) {
let BASE_PATH;

if (req) {
// Server side, communicate with our local API
const port = process.env.COMMUTER_PORT || 4000;
BASE_PATH = `http://127.0.0.1:${port}/`;
} else {
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import Link from "next/link";
class IndexPage extends React.Component<*> {
static async getInitialProps(ctx) {
if (ctx.res) {
// Server side, do a redirect using the HTTP response object
ctx.res.writeHead(302, { Location: "/view/" });
ctx.res.end();
} else {
// Client side redirect
document.location.pathname = "/view/";
}
return {};
Expand Down
4 changes: 3 additions & 1 deletion packages/frontend/pages/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Body from "../components/body";
import { Entry } from "../components/contents";

class ViewPage extends React.Component<*> {
static async getInitialProps({ req, pathname, asPath, query }) {
static async getInitialProps({ req, query }) {
// Later, we'll use this to fill in the notebook
// file data from the server side (or fallback to /api/contents)
// For now, leaving "server": boolean to assist in debugging
Expand All @@ -25,6 +25,7 @@ class ViewPage extends React.Component<*> {
let BASE_PATH;

if (req) {
// Server side, communicate with our local API
const port = process.env.COMMUTER_PORT || 4000;
BASE_PATH = `http://127.0.0.1:${port}/`;
} else {
Expand All @@ -46,6 +47,7 @@ class ViewPage extends React.Component<*> {
}

render() {
console.log(this.props.services);
if (this.props.statusCode) {
return <div>{`Nothing found for ${this.props.viewPath}`}</div>;
}
Expand Down

0 comments on commit 3da7c6f

Please sign in to comment.