-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --static flag to build script which allows to generate static htm…
…l for specific routes (#642)
- Loading branch information
Showing
5 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* React Starter Kit (https://www.reactstarterkit.com/) | ||
* | ||
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE.txt file in the root directory of this source tree. | ||
*/ | ||
|
||
import runServer from './runServer'; | ||
import fs from './lib/fs'; | ||
import fetch from 'node-fetch'; | ||
import { host } from '../src/config'; | ||
|
||
// Enter your paths here which you want to render as static | ||
const routes = [ | ||
'/', | ||
'/contact', | ||
'/login', | ||
'/register', | ||
'/about', | ||
'/privacy', | ||
'/404', // https://help.github.com/articles/creating-a-custom-404-page-for-your-github-pages-site/ | ||
]; | ||
|
||
async function render() { | ||
let server; | ||
await new Promise(resolve => (server = runServer(resolve))); | ||
|
||
await routes.reduce((promise, route) => promise.then(async () => { | ||
const url = `http://${host}${route}`; | ||
const dir = `build/public${route.replace(/[^\/]*$/, '')}`; | ||
const name = route.endsWith('/') ? 'index.html' : `${route.match(/[^/]+$/)[0]}.html`; | ||
const dist = `${dir}${name}`; | ||
const res = await fetch(url); | ||
const text = await res.text(); | ||
await fs.makeDir(dir); | ||
await fs.writeFile(dist, text); | ||
console.log(`${dist} => ${res.status} ${res.statusText}`); | ||
}), Promise.resolve()); | ||
|
||
server.kill('SIGTERM'); | ||
} | ||
|
||
export default render; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters