reload: Path not found for reload

I’ve started a node.js and express.js project and installed reload but I can’t get the path for the script to work correctly.

`var server = http.createServer(app);

reload(server, app);`

that’s in my www.js file.

when I try to point to the endpoint /reload/reload.js, I get a 404 error message

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 24 (15 by maintainers)

Most upvoted comments

For anyone else interested I got it working like this in version 1.1.1:

In my routing before the error handling:

app.get('/reloader', (req, res) => {
  res.type('text/javascript')
  res.sendFile(require.resolve('reload/lib/reload-client'))
});

On every page:

<script src="/reloader"></script>

When the app is served:

var server = http.createServer(app);
var reload = require('reload');
reload(server, {get: () => true});

@spikyjt Can confirm, I had the above problem in a vanilla express project and after commenting the 404 route reload.js loads.

/*// catch 404 and forward to error handler app.use(function(req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); }); */

I have this problem too, and I solved it by adding my own route for reload.js in my app.

I think the problem occurs when reload is invoked after a 404 route has already been set up, so the app never gets to the route for /reload/reload.js added by the reload module.

I suggest this could be fixed by separating the route code in the module out into another method which would be exposed by the module. Then the default method could take a parameter to include the route as it does now. We could then call the route generator method manually in a suitable place with out other routes if necessary.