Skip to content

Commit

Permalink
fix(server): only serve bundle if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Nov 11, 2016
1 parent 2aeecf8 commit 5460303
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,22 @@ nunjucks(app, {

app.use(serve('assets', path.join(__dirname, '../../public')));

const bundlePath = path.join(__dirname, '../../public/bundle.js');
if (fs.existsSync(bundlePath)) {
// always render index.html unless it's an API route
let indexHtml = fs.readFileSync(path.join(__dirname, '../../public/index.html'), 'utf8');
indexHtml = indexHtml.replace(/assets\//g, proxyPrefix + 'assets/');
const bundleJs = fs.readFileSync(path.join(__dirname, '../../public/bundle.js'), 'utf8');
app.use(function*(next) {
if (this.path.startsWith(`${proxyPrefix}db`) || this.path.startsWith(`${proxyPrefix}auth`)) {
yield next;
} else if (this.path.endsWith('/bundle.js')) {
this.body = bundleJs;
} else {
this.body = indexHtml;
}
});
let indexHtml = fs.readFileSync(path.join(__dirname, '../../public/index.html'), 'utf8');
indexHtml = indexHtml.replace(/assets\//g, proxyPrefix + 'assets/');
const bundleJs = fs.readFileSync(bundlePath, 'utf8');
app.use(function*(next) {
if (this.path.startsWith(`${proxyPrefix}db`) || this.path.startsWith(`${proxyPrefix}auth`)) {
yield next;
} else if (this.path.endsWith('/bundle.js')) {
this.body = bundleJs;
} else {
this.body = indexHtml;
}
});
}

const allowedOrigins = config.allowedOrigins;
debug(`allowed cors origins: ${allowedOrigins}`);
Expand Down

0 comments on commit 5460303

Please sign in to comment.