Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

Node server starts before the routes are loaded #75

Open
borekb opened this issue Apr 27, 2016 · 1 comment
Open

Node server starts before the routes are loaded #75

borekb opened this issue Apr 27, 2016 · 1 comment

Comments

@borekb
Copy link
Member

borekb commented Apr 27, 2016

On some occasions, I can get errors like this one:

TypeError: C:\Dev\VersionPress\docs-site\dist\views\layout.jade:37
   35|               li
   36|                 a(href="/#{language}") Home
 > 37|               each val in rootRoute['_routes']
   38|                 +traverseRoutes(val)
   39| 
   40| 

Cannot read property '_routes' of undefined
   at eval (eval at <anonymous> (C:\Dev\VersionPress\docs-site\node_modules\jade\lib\index.js:218:8), <anonymous>:360:24)
   at eval (eval at <anonymous> (C:\Dev\VersionPress\docs-site\node_modules\jade\lib\index.js:218:8), <anonymous>:390:4)
   at eval (eval at <anonymous> (C:\Dev\VersionPress\docs-site\node_modules\jade\lib\index.js:218:8), <anonymous>:586:22)
   at res (C:\Dev\VersionPress\docs-site\node_modules\jade\lib\index.js:219:38)
   at Object.exports.renderFile (C:\Dev\VersionPress\docs-site\node_modules\jade\lib\index.js:380:38)
   at Object.exports.renderFile (C:\Dev\VersionPress\docs-site\node_modules\jade\lib\index.js:370:21)
   at View.exports.__express [as engine] (C:\Dev\VersionPress\docs-site\node_modules\jade\lib\index.js:417:11)
   at View.render (C:\Dev\VersionPress\docs-site\node_modules\express\lib\view.js:126:8)
   at tryRender (C:\Dev\VersionPress\docs-site\node_modules\express\lib\application.js:639:10)
   at EventEmitter.render (C:\Dev\VersionPress\docs-site\node_modules\express\lib\application.js:591:3)

I think this is because in server.ts, the express server is started almost immediately but the site generally isn't prepare to take HTTP requests (building the routes takes some time).

This is problematic mostly in the npm run watch scenario where Browsersync will try to reload browsers as soon as the Node server restarts.

@borekb borekb added this to the Improvements milestone Apr 27, 2016
@borekb borekb added the bug label Apr 27, 2016
@octopuss
Copy link
Contributor

Could you please add RoutingService.getInstance(); somewhere to app.ts ? (import of service is also necessary)

I am unable to replicate it, but instantiation of RoutingService singleton in application initialization may help.

octopuss added a commit that referenced this issue May 3, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants