updated server startup to use a custom public folder

This commit is contained in:
bill bittner 2018-03-29 18:25:50 -07:00
parent 3a80c4fd3b
commit d52e5bf29a
3 changed files with 496 additions and 497 deletions

977
index.js

File diff suppressed because one or more lines are too long

View file

@ -12,9 +12,9 @@ module.exports = (helmet, html, preloadedState) => {
${helmet.meta.toString()}
${helmet.link.toString()}
<!--style sheets-->
<link rel="stylesheet" href="/assets/css/reset.css" type="text/css">
<link rel="stylesheet" href="/assets/css/general.css" type="text/css">
<link rel="stylesheet" href="/assets/css/mediaQueries.css" type="text/css">
<link rel="stylesheet" href="/static/assets/css/reset.css" type="text/css">
<link rel="stylesheet" href="/static/assets/css/general.css" type="text/css">
<link rel="stylesheet" href="/static/assets/css/mediaQueries.css" type="text/css">
<!--google font-->
<link href="https://fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet">
</head>
@ -25,7 +25,7 @@ module.exports = (helmet, html, preloadedState) => {
<script>
window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(/</g, '\\\u003c')}
</script>
<script src="/bundle/bundle.js"></script>
<script src="/static/bundle/bundle.js"></script>
</body>
</html>
`;

View file

@ -47,14 +47,14 @@ function Server () {
// set HTTP headers to protect against well-known web vulnerabilties
app.use(helmet());
// 'express.static' to serve static files from public directory
if (siteConfig.routes.public) {
if (siteConfig.routes.publicFolder) {
// take in a different public folder, so it can serve it's own bundle if needed
const { publicFolder } = siteConfig.routes;
app.use(express.static(publicFolder))
const publicFolder = Path.resolve(process.cwd(), siteConfig.routes.publicFolder);
app.use('/static', express.static(publicFolder));
logger.info('serving static files from custom path:', publicFolder);
} else {
const publicPath = Path.resolve(__dirname, 'public');
app.use(express.static(publicPath));
app.use('/static', express.static(publicPath));
logger.info('serving static files from default path:', publicPath);
};
// 'body parser' for parsing application/json