This repository has been archived by the owner on Sep 11, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(server): server entry point now throws if react router returns no…
… initial state (fixes bad urls breaking server)
- Loading branch information
David Zukowski
committed
Aug 16, 2015
1 parent
0453f09
commit b599fa8
Showing
2 changed files
with
21 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
const router = require('../../dist/server'), | ||
const runRouter = require('../../dist/server'), | ||
USE_CACHE = process.env.NODE_ENV === 'production'; | ||
|
||
function renderIntoTemplate (template, content) { | ||
return template.replace('${content}', content); | ||
} | ||
|
||
module.exports = function makeRenderRouteMiddleware (template) { | ||
return function *renderRouteMiddleware () { | ||
const rendered = yield router(this.request); | ||
return function *renderRouteMiddleware (next) { | ||
try { | ||
const rendered = yield runRouter(this.request); | ||
|
||
this.body = renderIntoTemplate(template, rendered); | ||
this.body = renderIntoTemplate(template, rendered); | ||
} catch (e) { | ||
console.log(e); | ||
yield next; | ||
} | ||
}; | ||
}; |
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