@@ -7,12 +7,15 @@ import { ReduxAsyncConnect, loadOnServer } from 'redux-connect';
77import createHistory from 'react-router/lib/createMemoryHistory' ;
88import { Provider } from 'react-redux' ;
99import cookie from 'react-cookie' ;
10+ import raven from 'raven' ;
11+ import errorhandler from 'errorhandler' ;
1012
11-
13+ import config from 'config' ;
1214import expressConfig from 'server/config/express' ;
1315
1416const pretty = new PrettyError ( ) ;
1517const server = express ( ) ;
18+
1619expressConfig ( server ) ;
1720
1821import routes from './src/routes' ;
@@ -26,6 +29,7 @@ import { setUserAgent } from './src/redux/modules/audioplayer';
2629import { setOption } from './src/redux/modules/options' ;
2730
2831// Use varnish for the static routes, which will cache too
32+ server . use ( raven . middleware . express . requestHandler ( config . sentryServer ) ) ;
2933
3034server . use ( ( req , res , next ) => {
3135 cookie . plugToRequest ( req , res ) ;
@@ -59,28 +63,40 @@ server.use((req, res, next) => {
5963 res . status ( 500 ) . send ( error ) ;
6064 } else if ( renderProps ) {
6165 loadOnServer ( { ...renderProps , store, helpers : { client } } ) . then ( ( ) => {
62- const component = ReactDOM . renderToString (
66+ const component = (
6367 < Provider store = { store } >
6468 < ReduxAsyncConnect { ...renderProps } />
6569 </ Provider >
6670 ) ;
6771
68- debug ( 'Server' , 'Rendering Application component into html' ) ;
69- debug ( 'Server' , 'Sending markup' ) ;
7072 res . type ( 'html' ) ;
7173 res . setHeader ( 'Cache-Control' , 'public, max-age=31557600' ) ;
72- res . status ( 200 ) . send ( '<!doctype html>\n' + ReactDOM . renderToString (
74+ res . status ( 200 ) ;
75+ debug ( 'Server' , 'Sending markup' ) ;
76+ res . send ( '<!doctype html>\n' + ReactDOM . renderToString (
7377 < Html
7478 component = { component }
7579 store = { store }
7680 assets = { webpack_isomorphic_tools . assets ( ) }
7781 />
7882 ) ) ;
79- } ) ;
83+ } ) . catch ( next ) ;
8084 }
8185 } ) ;
8286} ) ;
8387
88+ server . use ( raven . middleware . express . errorHandler ( config . sentryServer ) ) ;
89+
90+ if ( process . env . NODE_ENV === 'development' ) {
91+ // only use in development
92+ server . use ( errorhandler ( ) ) ;
93+ } else {
94+ server . use ( ( req , res ) => {
95+ res . status ( 500 ) ;
96+ res . send ( 'OOPS' ) ;
97+ } ) ;
98+ }
99+
84100const port = process . env . PORT || 8000 ;
85101
86102export default function serve ( cb ) {
@@ -90,6 +106,7 @@ export default function serve(cb) {
90106 ==> ✅ Server is listening at http://localhost:${ port }
91107 ==> 🎯 API at ${ process . env . API_URL }
92108 ` ) ;
109+ Object . keys ( config ) . forEach ( key => config [ key ] . constructor . name !== 'Object' && console . info ( `==> ${ key } ` , config [ key ] ) ) ;
93110
94111 cb && cb ( this ) ;
95112 } ) ;
0 commit comments