├── client ├── blog.js └── client.js ├── public ├── logo.png └── style.css ├── .gitignore ├── server └── getPosts.js ├── package.json ├── webpack.config.js ├── README.md ├── server.js └── LICENSE /client/blog.js: -------------------------------------------------------------------------------- 1 | const blog = () => 'here will be blog'; 2 | 3 | export default blog; 4 | -------------------------------------------------------------------------------- /public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Everettss/isomorphic-pwa/HEAD/public/logo.png -------------------------------------------------------------------------------- /client/client.js: -------------------------------------------------------------------------------- 1 | import blog from './blog'; 2 | 3 | const renderBlog = () => { 4 | document.getElementById('app').innerHTML = blog(); 5 | }; 6 | 7 | setTimeout(() => { 8 | renderBlog(); 9 | }, 1000); 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /public/script.js 3 | server.build.js 4 | 5 | # misc 6 | .DS_Store 7 | .env.local 8 | .env.development.local 9 | .env.test.local 10 | .env.production.local 11 | 12 | npm-debug.log* 13 | yarn-debug.log* 14 | yarn-error.log* 15 | 16 | .idea 17 | 18 | 19 | -------------------------------------------------------------------------------- /server/getPosts.js: -------------------------------------------------------------------------------- 1 | const faker = require('faker'); 2 | 3 | const makePost = () => ({ 4 | avatar: faker.image.avatar(), 5 | title: faker.lorem.sentence(), 6 | date: `${faker.date.recent()}`, 7 | teaser: faker.lorem.paragraph(), 8 | }); 9 | 10 | const getPosts = cb => { 11 | setTimeout(() => { 12 | const posts = Array.from(new Array(5)).map(makePost); 13 | cb(posts); 14 | }, 1000); 15 | }; 16 | 17 | module.exports = getPosts; 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "isomorphic-pwa", 3 | "version": "1.0.0", 4 | "description": "Example how to combine PWA with isomorphic rendering", 5 | "main": "server.js", 6 | "scripts": { 7 | "start": "./node_modules/webpack/bin/webpack.js -w", 8 | "build": "./node_modules/webpack/bin/webpack.js -p" 9 | }, 10 | "author": "Michal Janaszek", 11 | "license": "MIT", 12 | "dependencies": { 13 | "babel-core": "^6.26.0", 14 | "babel-loader": "^7.1.2", 15 | "babel-preset-env": "^1.6.1", 16 | "express": "^4.16.2", 17 | "faker": "^4.1.0", 18 | "webpack": "^3.8.1", 19 | "webpack-node-externals": "^1.6.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | entry: path.resolve(__dirname, 'client', 'client.js'), 5 | output: { 6 | path: path.resolve(__dirname, 'public'), 7 | filename: 'script.js', 8 | }, 9 | module: { 10 | rules: [ 11 | { 12 | test: /\.js$/, 13 | exclude: /node_modules/, 14 | use: { 15 | loader: 'babel-loader', 16 | options: { 17 | presets: ['babel-preset-env'], 18 | }, 19 | }, 20 | }, 21 | ], 22 | }, 23 | }; 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # isomorphic-pwa 2 | Example how to combine PWA with isomorphic rendering (SSR) used in article https://michaljanaszek.com/blog/combine-pwa-and-isomorphic-rendering 3 | 4 | ## Build project 5 | `npm install` - surprised? 6 | 7 | `npm run build` - build project 8 | 9 | or `npm run start` - develop project (the same as `build` but with watch) 10 | 11 | 12 | ## Run project 13 | after `start` or `build` run server: 14 | 15 | `node server` for stage 1 - 3 16 | 17 | `node server.build` for stage 4 - 5 18 | 19 | ## Chapters 20 | Project contains branches stage1 - stage5, each branch represents chapter in [article](https://michaljanaszek.com/blog/combine-pwa-and-isomorphic-rendering). 21 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | const getPosts = require('./server/getPosts'); 4 | 5 | app.use(express.static('public')); 6 | 7 | const html = () => ` 8 | 9 |
10 | 11 | 12 | 13 | 14 |