Skip to content

Pwa support #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
pwa support
  • Loading branch information
liuliquan authored and ThomasKranitsas committed Aug 16, 2018
commit 9e01fa2de1110fd8255f59d6cafbb89c798ad281
24 changes: 18 additions & 6 deletions __tests__/server/__snapshots__/renderer.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

exports[`Base rendering of HTML template 1`] = `
"<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>


<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"
id=\\"tru-style\\"
Expand Down Expand Up @@ -40,10 +42,12 @@ exports[`Base rendering of HTML template 1`] = `

exports[`Config overriding for injection 1`] = `
"<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>


<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"
id=\\"tru-style\\"
Expand Down Expand Up @@ -78,10 +82,12 @@ exports[`Config overriding for injection 1`] = `

exports[`Hemlet integration works 1`] = `
"<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>
<title data-react-helmet=\\"true\\">Test Page Title</title>
<meta data-react-helmet=\\"true\\" property=\\"description\\" content=\\"Test Page Description\\"/>
<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"
id=\\"tru-style\\"
Expand Down Expand Up @@ -116,10 +122,12 @@ exports[`Hemlet integration works 1`] = `

exports[`Injection of additional JS scripts 1`] = `
"<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>


<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"
id=\\"tru-style\\"
Expand Down Expand Up @@ -154,10 +162,12 @@ exports[`Injection of additional JS scripts 1`] = `

exports[`Server-side rendering (SSR); injection of CSS chunks & Redux state 1`] = `
"<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>
<title data-react-helmet=\\"true\\"></title>

<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"
id=\\"tru-style\\"
Expand Down Expand Up @@ -193,10 +203,12 @@ exports[`Server-side rendering (SSR); injection of CSS chunks & Redux state 1`]
exports[`Setting of response HTTP status the server-side rendering 1`] = `
"HTTP STATUS: 404
<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>
<title data-react-helmet=\\"true\\"></title>

<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"
id=\\"tru-style\\"
Expand Down
4 changes: 3 additions & 1 deletion src/server/renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,12 @@ export default function factory(webpackConfig, options) {

res.send((
`<!DOCTYPE html>
<html>
<html lang="en">
<head>
${helmet ? helmet.title.toString() : ''}
${helmet ? helmet.meta.toString() : ''}
<meta name="theme-color" content="#FFFFFF"/>
<link rel="manifest" href="${publicPath}manifest.json">
<link
href="${publicPath}main-${timestamp}.css"
id="tru-style"
Expand Down
17 changes: 13 additions & 4 deletions src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ export default async function factory(webpackConfig, options) {
}),
}));

const exludeSW = middleware => (req, res, next) => {
if (req.url.indexOf('/sw.js') > -1) {
next();
return;
}
middleware(req, res, next);
};

/* Setup of Hot Module Reloading for development environment.
* These dependencies are not used, nor installed for production use,
* hence we should violate some import-related lint rules. */
Expand All @@ -56,18 +64,19 @@ export default async function factory(webpackConfig, options) {
const webpackHotMiddleware = require('webpack-hot-middleware');
const compiler = webpack(webpackConfig);
compiler.apply(new webpack.ProgressPlugin());
server.use(webpackDevMiddleware(compiler, {
server.use(exludeSW(webpackDevMiddleware(compiler, {
name: 'main.js',
publicPath,
serverSideRender: true,
}));
server.use(webpackHotMiddleware(compiler));
})));
server.use(exludeSW(webpackHotMiddleware(compiler)));
}
/* eslint-enable global-require */
/* eslint-enable import/no-extraneous-dependencies */
/* eslint-enable import/no-unresolved */

server.use(publicPath, express.static(webpackConfig.output.path));
server.use(publicPath, exludeSW(express.static(webpackConfig.output.path)));

if (options.onExpressJsSetup) {
await options.onExpressJsSetup(server);
}
Expand Down