You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or 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
This PR sets up code hot-swapping on the server without a full restart (but still requiring a refresh of the browser window). Crazy-fast development speed!
Overview of process:
reloadable is called with a path to an app (client, api, etc) as well as a callback function that is executed whenever files with that appPath change
When a source-code change is detected an internal lookup is made to Node, scanning its require cache
If found, it is cleared via delete require.cache[id]
When the browser is reloaded the callback re-requires the initial app and since the module is no longer in the cache node re-caches it, effectively hot-reloading the code during runtime.
Example:
import{createReloadable,isDevelopment}from'lib/reloadable'
...
if(isDevelopment){constreloadAndMount=createReloadable(app)// Note that if you need to mount an app at a particular root (`/api`), pass // in `mountPoint` as an option.app.use('/api',reloadAndMount(path.resolve(__dirname,'api'),{mountPoint: '/api'}))// Otherwise, just pass in the path to the express app and everything is taken care of reloadAndMount(path.resolve(__dirname,'client'))}else{app.use('/api',require('./api')app.use(require('./client')}
The reason will be displayed to describe this comment to others. Learn more.
Ah right this comment can probably be removed since it's pretty old and we actually benefit from not sharing req.user because it keeps our API stateless.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR sets up code hot-swapping on the server without a full restart (but still requiring a refresh of the browser window). Crazy-fast development speed!
Overview of process:
reloadable
is called with a path to an app (client
,api
, etc) as well as a callback function that is executed whenever files with that appPath changerequire
cachedelete require.cache[id]
Example: