Skip to content

Commit

Permalink
Merge pull request #213 from labzero/develop
Browse files Browse the repository at this point in the history
Merge to master
  • Loading branch information
JeffreyATW authored May 18, 2018
2 parents 658b261 + 9602f76 commit 2fdff43
Show file tree
Hide file tree
Showing 28 changed files with 253 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
},
},
],
'@babel/preset-stage-2',
["@babel/preset-stage-2", { "decoratorsLegacy": true }],
'@babel/preset-flow',
'@babel/preset-react',
],
Expand Down
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ HONEYBADGER_API_KEY=

# SendGrid info for email notifications
SENDGRID_API_KEY=

# Set as true to run https locally, add self-signed certificate in cert folder to trusted certificates
USE_HTTPS=
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ node build/server.js

You can modify `tools/deploy.js` as needed to work with your deployment strategy.

## Service Worker

To run the service worker locally, follow the above steps to run the production server. After testing the service worker, be sure to unregister the service worker in the browser (or close all local Lunch tabs) to avoid issues when testing on the development server.

## Testing

### Unit tests
Expand Down
36 changes: 16 additions & 20 deletions cert/server.crt
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
-----BEGIN CERTIFICATE-----
MIIDljCCAn4CCQDKlarFMPQQbDANBgkqhkiG9w0BAQsFADCBjDELMAkGA1UEBhMC
VVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28x
ETAPBgNVBAoMCExhYiBaZXJvMRkwFwYDVQQDDBBsb2NhbC5sdW5jaC5waW5rMSIw
IAYJKoZIhvcNAQkBFhNqZWZmcmV5QGxhYnplcm8uY29tMB4XDTE4MDQyNjIxMjIy
NFoXDTE5MDQyNjIxMjIyNFowgYwxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxp
Zm9ybmlhM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jYWwubHVuY2gucGluazCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBALtMxMSaciE+9/GPzOhtG8b9oeCSIIBKd8FY
1JQ+s2ZUuDppA46hCzLjuhoHMuJehJKYlctZGDYVE2jRYCC/mdFN8jWfHE1sqp9A
Q/qP6vsTvPpfmKcnu/x62TLPH7ZrNvwhiv18YxszvJQAhdGBW8geftMH8x9PfznQ
yzkIDTROeAZbnY29PxQTmVwx90o6CKfLaBAX/Z6ZkFAMio8v3GGuW6bJMo+g7Lz0
r2KzzZEZp7oUCP5tw1uvAjzO4XD56vNdjrBymrySza2qCM7UNbMEWExtMqvsUK6C
5HcnT3PyWARaJH8G5wQpvFqNbW18nQoh9owoa/hcYhxR2nBRQOECAwEAAaMhMB8w
HQYDVR0RBBYwFIISKi5sb2NhbC5sdW5jaC5waW5rMA0GCSqGSIb3DQEBCwUAA4IB
AQCqystbK46mhrfCWKnS2qlCkuU1YT8xGaOFqb8/f+rNq6UonIZ38vcHUn4k9UcT
HYhVkul36YK85KMq9E6tlmuGxgl8hg021bPgi/0Y8x/4EAWIVYM2IARQhIgEa5+F
30u4Rf+OZhjt4EQ4QUoyOynXLrA2sFnzApeFYhmDwXtkB9umECSF1CLDc8l+zLZB
utBZwdzVSHs8atnZTdCLHwo42egWJVecA8CbNuQZ0PCEF7hmMoVH9Iln1Fvidhp3
gwI/NnK7fZUWEee4nuinX2OIybPtofkfXjxljcC8bubslmceAjc4rSxGwuY61lvN
B8NDHd+xb30jLmlnr5x+pq7l
-----END CERTIFICATE-----
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@
"webpack-bundle-analyzer": "^2.11.1",
"webpack-dev-middleware": "^3.1.2",
"webpack-hot-middleware": "^2.21.2",
"webpack-node-externals": "^1.7.2"
"webpack-node-externals": "^1.7.2",
"workbox-webpack-plugin": "^3.2.0"
},
"lint-staged": {
"*.{js,jsx}": ["eslint --no-ignore --fix", "git add --force"],
Expand Down
8 changes: 7 additions & 1 deletion public/site.webmanifest
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"short_name": "Lunch",
"name": "Lunch",
"description": "A simple lunch voting app for you and your team. Search nearby restaurants, add them to your list, vote for as many as you like, and decide on today’s pick!",
"icons": [
{
"src": "icon.png",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "/"
"start_url": "/",
"display": "standalone",
"theme_color": "#FFC0CB",
"background_color": "#FFF"
}
2 changes: 1 addition & 1 deletion src/components/ErrorPage/ErrorPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function ErrorPage({ error }) {
let errorMessage = null;

if (error.status === 404) {
title = 'Page Not Found';
title = 'Page not found';
content = 'Sorry, the page you were trying to view does not exist.';
} else if (process.env.NODE_ENV !== 'production') {
errorMessage = <pre>{error.stack}</pre>;
Expand Down
2 changes: 2 additions & 0 deletions src/components/Html.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Html extends Component {
<meta property="twitter:card" content="summary" />
<meta property="twitter:site" content="labzero" />
<meta property="twitter:image" content={`${root}/tile.png`} />
<meta name="theme-color" content="#FFC0CB" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito:400,900" />
{scripts.map(script => (
Expand All @@ -92,6 +93,7 @@ class Html extends Component {
<body>
<div id="app" dangerouslySetInnerHTML={{ __html: children }} />
<script dangerouslySetInnerHTML={{ __html: `window.App=${serialize(app)}` }} />
{!module.hot && <script dangerouslySetInnerHTML={{ __html: `if ('serviceWorker' in navigator) { window.addEventListener('load', () => { navigator.serviceWorker.register('/service-worker.js').then(function(registration) {registration.addEventListener('updatefound', () => {window.swUpdate = true; }); }); }); }` }} />}
{apikey && <script src={`https://maps.googleapis.com/maps/api/js?key=${apikey}&libraries=places&v=3`} />}
{scripts.map(script => <script key={script} src={script} />)}
</body>
Expand Down
7 changes: 6 additions & 1 deletion src/components/Link/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ class Link extends React.Component {
}

event.preventDefault();
history.push(this.props.to);

if (window.swUpdate) {
window.location = this.props.to;
} else {
history.push(this.props.to);
}
};

render() {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/helpers/render404.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import LayoutContainer from '../../components/Layout/LayoutContainer';
import NotFound from '../not-found/NotFound';

const title = 'Page Not Found';
const title = 'Page not found';

export default (context) => ({
chunks: ['not-found'],
Expand Down
4 changes: 3 additions & 1 deletion src/routes/helpers/rootAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export default async ({ next }) => {

// Provide default values for title, description etc.
const title = 'Lunch';
if (route.title) {
if (route.fullTitle) {
route.title = route.fullTitle;
} else if (route.title) {
route.title = `${title} | ${route.title}`;
} else {
route.title = title;
Expand Down
1 change: 1 addition & 0 deletions src/routes/login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function action(context) {
<LoginContainer team={subdomain} next={next} />
</LayoutContainer>
),
title: 'Log in',
}));
}

Expand Down
1 change: 1 addition & 0 deletions src/routes/main/invitation/create/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export default (context) => {
<Create success={success} token={token} />
</LayoutContainer>
),
title: 'Invitation',
};
};
1 change: 1 addition & 0 deletions src/routes/main/invitation/new/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export default (context) => {
<New email={email} />
</LayoutContainer>
),
title: 'Invitation',
};
};
1 change: 1 addition & 0 deletions src/routes/main/landing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export default (context) => {
<Landing />
</LayoutContainer>
),
fullTitle: 'Lunch – Team voting for nearby restaurants',
}));
};
2 changes: 1 addition & 1 deletion src/routes/main/new-team/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import LayoutContainer from '../../../components/Layout/LayoutContainer';
import renderIfHasName from '../../helpers/renderIfHasName';
import NewTeamContainer from './NewTeamContainer';

const title = 'New Team';
const title = 'New team';

export default (context) => renderIfHasName(context, () => ({
title,
Expand Down
1 change: 1 addition & 0 deletions src/routes/main/password/create/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default (context) => {
<Create success={success} />
</LayoutContainer>
),
title: 'Reset password',
};
});
};
1 change: 1 addition & 0 deletions src/routes/main/password/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default (context) => {
<Edit token={token} />
</LayoutContainer>
),
title: 'Reset password',
};
});
};
1 change: 1 addition & 0 deletions src/routes/main/password/new/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ export default (context) => {
<New email={email} />
</LayoutContainer>
),
title: 'Reset password',
}));
};
1 change: 1 addition & 0 deletions src/routes/main/teams/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import TeamsContainer from './TeamsContainer';
export default (context) => renderIfHasName(context, () => ({
chunks: ['teams'],
component: <LayoutContainer path={context.pathname}><TeamsContainer /></LayoutContainer>,
title: 'My teams',
}));
1 change: 1 addition & 0 deletions src/routes/main/users/create/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default (context) => {
<Create />
</LayoutContainer>
),
title: 'New user',
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/routes/main/users/new/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export default (context) => {
<LayoutContainer path={context.pathname}>
<New email={email} />
</LayoutContainer>
)
),
title: 'New user',
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const accessLogStream = rfs('access.log', {
const app = express();

let internalWsServer;
if (module.hot) {
if (process.env.USE_HTTPS === 'true') {
// use self-signed cert locally
const options = {
key: fs.readFileSync(path.join(__dirname, '../cert/server.key')),
Expand Down Expand Up @@ -358,7 +358,7 @@ const render = async (req, res, next) => {
const data = { ...route,
apikey: process.env.GOOGLE_CLIENT_APIKEY || '',
title: route.title || 'Lunch',
description: 'An app for groups to decide on nearby lunch options.',
description: 'A simple lunch voting app for you and your team. Search nearby restaurants, add them to your list, vote for as many as you like, and decide on today’s pick!',
body: '',
root: generateUrl(req, req.get('host')),
};
Expand Down Expand Up @@ -442,7 +442,7 @@ app.use(Honeybadger.errorHandler); // Use *after* all other app middleware.
//
// Launch the server
// -----------------------------------------------------------------------------
if (module.hot) {
if (process.env.USE_HTTPS === 'true') {
wsServer.listen(config.wsPort, () => {
/* eslint-disable no-console */
console.log(`The websockets server is running at https://local.lunch.pink:${config.wsPort}/`);
Expand Down
24 changes: 24 additions & 0 deletions src/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* global workbox */
/* eslint-disable no-restricted-globals */

// eslint-disable-next-line no-underscore-dangle
workbox.precaching.precacheAndRoute(self.__precacheManifest || []);

// Cache the index page
workbox.routing.registerRoute(
context => context.url.pathname.indexOf('/api') !== 0 && context.url.pathname.indexOf('/assets') !== 0,
workbox.strategies.cacheFirst({
cacheName: 'pages',
plugins: [
new workbox.expiration.Plugin({
maxAgeSeconds: 30 * 24 * 60 * 60, // 24 hours
}),
],
}),
);

// eslint-disable-next-line no-unused-vars
self.addEventListener('install', event => {
// Activate new service worker as soon as it's installed
self.skipWaiting();
});
6 changes: 6 additions & 0 deletions src/styles/globalCss.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ a {
border-color: $border-color;
}
}

// causes google maps touch warning to appear above markers
.gm-style-pbc {
z-index: 5 !important;
pointer-events: none;
}
2 changes: 1 addition & 1 deletion test/integration/other.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('other pages', () => {
await page.goto('http://local.lunch.pink:3000/404');
await page.waitForSelector('#app', helpers.waitOptions);
const content = await page.content();
expect(content).to.contain('Page Not Found');
expect(content).to.contain('Page not found');
});
});
});
10 changes: 8 additions & 2 deletions tools/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import webpack from 'webpack';
import WebpackAssetsManifest from 'webpack-assets-manifest';
import nodeExternals from 'webpack-node-externals';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import {InjectManifest} from 'workbox-webpack-plugin';
import overrideRules from './lib/overrideRules';
import pkg from '../package.json';

Expand Down Expand Up @@ -88,7 +89,7 @@ const config = {
],
// Experimental ECMAScript proposals
// https://babeljs.io/docs/plugins/#presets-stage-x-experimental-presets-
'@babel/preset-stage-2',
["@babel/preset-stage-2", { "decoratorsLegacy": true }],
// Flow
// https://github.com/babel/babel/tree/master/packages/babel-preset-flow
'@babel/preset-flow',
Expand Down Expand Up @@ -368,7 +369,7 @@ const clientConfig = {
),
];
return acc;
}, Object.create(null));
}, Object.create(null));
fs.writeFileSync(chunkFileName, JSON.stringify(chunkFiles, null, 2));
} catch (err) {
console.error(`ERROR: Cannot write ${chunkFileName}: `, err);
Expand All @@ -384,6 +385,11 @@ const clientConfig = {
// https://github.com/th0r/webpack-bundle-analyzer
...(isAnalyze ? [new BundleAnalyzerPlugin()] : []),
]),

new InjectManifest({
swSrc: './src/service-worker.js',
swDest: resolvePath(BUILD_DIR, 'public/service-worker.js'),
}),
],

// Move modules that occur in multiple entry chunks to a new entry chunk (the commons chunk).
Expand Down
Loading

0 comments on commit 2fdff43

Please sign in to comment.