Skip to content

Commit

Permalink
client: Add static html export using next@3
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Jul 2, 2017
1 parent 321fdb6 commit 9251d79
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.next
out
5 changes: 1 addition & 4 deletions client/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ const enhance = withContext({
isMobile: isMobile(userAgent),
}));

const Layout = ({
children,
userAgent,
}) => (
const Layout = ({ children }) => (
<ThemeProvider theme={createUwaveTheme()}>
<div className="app">
<SSR />
Expand Down
5 changes: 5 additions & 0 deletions client/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ exports.webpack = (config) => {

return config
}

exports.exportPathMap = () => ({
'/': { page: '/' },
'/about': { page: '/about' }
})
5 changes: 4 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"babel-plugin-transform-inline-environment-variables": "^6.8.0",
"babel-preset-env": "^1.5.2",
"ecstatic": "^2.2.1",
"is-mobile": "^0.2.2",
"isomorphic-fetch": "^2.2.1",
"material-ui": "^1.0.0-alpha.20",
Expand All @@ -22,6 +23,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"deploy": "now -e HUB_SERVER=https://announce.u-wave.net/"
"deploy": "now -e HUB_SERVER=https://announce.u-wave.net/",
"export": "next build && next export -o out",
"static": "ecstatic out"
}
}
3 changes: 2 additions & 1 deletion client/pages/about.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import Markdown from 'react-markdown';
import getUserAgent from '../util/getUserAgent';
import Layout from '../components/Layout';

const text = `
Expand All @@ -21,7 +22,7 @@ const Image = props => (
export default class About extends React.Component {
static async getInitialProps({ req }) {
return {
userAgent: req ? req.headers['user-agent'] : navigator.userAgent,
userAgent: getUserAgent(req),
};
}

Expand Down
7 changes: 4 additions & 3 deletions client/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import fetch from 'isomorphic-fetch';
import ms from 'ms';
import { CircularProgress } from 'material-ui/Progress';

import getUserAgent from '../util/getUserAgent';
import Layout from '../components/Layout';
import Loading from '../components/Loading';
import ServerListing from '../components/ServerListing';
Expand All @@ -27,11 +27,12 @@ async function loadServers() {

export default class App extends React.Component {
static async getInitialProps({ req }) {
const isExporting = req && !req.headers && typeof navigator === 'undefined';
return {
// If we're serving a new request, preload the servers.
// If we're transitioning on the client, show a loading indicator.
servers: req ? await loadServers() : null,
userAgent: req ? req.headers['user-agent'] : navigator.userAgent,
servers: req && !isExporting ? await loadServers() : null,
userAgent: getUserAgent(req),
};
}

Expand Down
10 changes: 10 additions & 0 deletions client/util/getUserAgent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function getUserAgent(req) {
if (req && req.headers) {
return req.headers['user-agent'];
}
if (typeof navigator !== 'undefined' && navigator.userAgent) {
return navigator.userAgent;
}
return 'all';
}

0 comments on commit 9251d79

Please sign in to comment.