Skip to content

Commit 9e01fa2

Browse files
liuliquanThomasKranitsas
authored andcommitted
pwa support
1 parent 3d091e6 commit 9e01fa2

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

__tests__/server/__snapshots__/renderer.jsx.snap

+18-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
exports[`Base rendering of HTML template 1`] = `
44
"<!DOCTYPE html>
5-
<html>
5+
<html lang=\\"en\\">
66
<head>
77
88
9+
<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
10+
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
911
<link
1012
href=\\"/test/public/path/main-1511941200000.css\\"
1113
id=\\"tru-style\\"
@@ -40,10 +42,12 @@ exports[`Base rendering of HTML template 1`] = `
4042

4143
exports[`Config overriding for injection 1`] = `
4244
"<!DOCTYPE html>
43-
<html>
45+
<html lang=\\"en\\">
4446
<head>
4547
4648
49+
<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
50+
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
4751
<link
4852
href=\\"/test/public/path/main-1511941200000.css\\"
4953
id=\\"tru-style\\"
@@ -78,10 +82,12 @@ exports[`Config overriding for injection 1`] = `
7882

7983
exports[`Hemlet integration works 1`] = `
8084
"<!DOCTYPE html>
81-
<html>
85+
<html lang=\\"en\\">
8286
<head>
8387
<title data-react-helmet=\\"true\\">Test Page Title</title>
8488
<meta data-react-helmet=\\"true\\" property=\\"description\\" content=\\"Test Page Description\\"/>
89+
<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
90+
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
8591
<link
8692
href=\\"/test/public/path/main-1511941200000.css\\"
8793
id=\\"tru-style\\"
@@ -116,10 +122,12 @@ exports[`Hemlet integration works 1`] = `
116122

117123
exports[`Injection of additional JS scripts 1`] = `
118124
"<!DOCTYPE html>
119-
<html>
125+
<html lang=\\"en\\">
120126
<head>
121127
122128
129+
<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
130+
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
123131
<link
124132
href=\\"/test/public/path/main-1511941200000.css\\"
125133
id=\\"tru-style\\"
@@ -154,10 +162,12 @@ exports[`Injection of additional JS scripts 1`] = `
154162

155163
exports[`Server-side rendering (SSR); injection of CSS chunks & Redux state 1`] = `
156164
"<!DOCTYPE html>
157-
<html>
165+
<html lang=\\"en\\">
158166
<head>
159167
<title data-react-helmet=\\"true\\"></title>
160168
169+
<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
170+
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
161171
<link
162172
href=\\"/test/public/path/main-1511941200000.css\\"
163173
id=\\"tru-style\\"
@@ -193,10 +203,12 @@ exports[`Server-side rendering (SSR); injection of CSS chunks & Redux state 1`]
193203
exports[`Setting of response HTTP status the server-side rendering 1`] = `
194204
"HTTP STATUS: 404
195205
<!DOCTYPE html>
196-
<html>
206+
<html lang=\\"en\\">
197207
<head>
198208
<title data-react-helmet=\\"true\\"></title>
199209
210+
<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
211+
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
200212
<link
201213
href=\\"/test/public/path/main-1511941200000.css\\"
202214
id=\\"tru-style\\"

src/server/renderer.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,12 @@ export default function factory(webpackConfig, options) {
184184

185185
res.send((
186186
`<!DOCTYPE html>
187-
<html>
187+
<html lang="en">
188188
<head>
189189
${helmet ? helmet.title.toString() : ''}
190190
${helmet ? helmet.meta.toString() : ''}
191+
<meta name="theme-color" content="#FFFFFF"/>
192+
<link rel="manifest" href="${publicPath}manifest.json">
191193
<link
192194
href="${publicPath}main-${timestamp}.css"
193195
id="tru-style"

src/server/server.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ export default async function factory(webpackConfig, options) {
4444
}),
4545
}));
4646

47+
const exludeSW = middleware => (req, res, next) => {
48+
if (req.url.indexOf('/sw.js') > -1) {
49+
next();
50+
return;
51+
}
52+
middleware(req, res, next);
53+
};
54+
4755
/* Setup of Hot Module Reloading for development environment.
4856
* These dependencies are not used, nor installed for production use,
4957
* hence we should violate some import-related lint rules. */
@@ -56,18 +64,19 @@ export default async function factory(webpackConfig, options) {
5664
const webpackHotMiddleware = require('webpack-hot-middleware');
5765
const compiler = webpack(webpackConfig);
5866
compiler.apply(new webpack.ProgressPlugin());
59-
server.use(webpackDevMiddleware(compiler, {
67+
server.use(exludeSW(webpackDevMiddleware(compiler, {
6068
name: 'main.js',
6169
publicPath,
6270
serverSideRender: true,
63-
}));
64-
server.use(webpackHotMiddleware(compiler));
71+
})));
72+
server.use(exludeSW(webpackHotMiddleware(compiler)));
6573
}
6674
/* eslint-enable global-require */
6775
/* eslint-enable import/no-extraneous-dependencies */
6876
/* eslint-enable import/no-unresolved */
6977

70-
server.use(publicPath, express.static(webpackConfig.output.path));
78+
server.use(publicPath, exludeSW(express.static(webpackConfig.output.path)));
79+
7180
if (options.onExpressJsSetup) {
7281
await options.onExpressJsSetup(server);
7382
}

0 commit comments

Comments
 (0)