Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path not found for reload #56

Closed
dadixon opened this issue Dec 15, 2016 · 24 comments
Closed

Path not found for reload #56

dadixon opened this issue Dec 15, 2016 · 24 comments

Comments

@dadixon
Copy link

dadixon commented Dec 15, 2016

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

@alallier
Copy link
Owner

You need to include this <script src="/reload/reload.js"></script> in your HTML. Also did you take a look at the sample app?

@dadixon
Copy link
Author

dadixon commented Dec 15, 2016

I've added that in as well. When I restart the server, I get this message. GET /reload/reload.js 404 13.711 ms - 1963. It never creates the endpoint for reload for me.

@alallier
Copy link
Owner

You installed, required, and called reload correctly in you www.js file?

@dadixon
Copy link
Author

dadixon commented Dec 15, 2016

Yes. I ran npm install --save reload. Inside my www file, it looks like this:
`var reload = require('reload');

/**

  • Get port from environment and store in Express.
    */

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**

  • Create HTTP server.
    */

var server = http.createServer(app);

reload(server, app);
console.log('reload');

/**

  • Listen on provided port, on all network interfaces.
    */

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);`

Inside my index.ejs file, it looks like this:
<script src="/reload/reload.js"></script>

@alallier
Copy link
Owner

alallier commented Dec 15, 2016

Looks alright. Are you able to upload it to a test repo, so I can check it out?

@dadixon
Copy link
Author

dadixon commented Dec 15, 2016

I will do that for you and give you the details

@dadixon
Copy link
Author

dadixon commented Dec 16, 2016

@dadixon
Copy link
Author

dadixon commented Dec 19, 2016

Any ideas?

@alallier
Copy link
Owner

Busy weekend, will check it out tonight for you.

@Eamonnzhang
Copy link

i have this problem, too

@alallier
Copy link
Owner

Sorry I've been busy, I will make it a point to check it out for you both this weekend

@alallier
Copy link
Owner

@dadixon I went to check out your repo and the link is dead.

@Eamonnzhang Can you provide more details?

@spikyjt
Copy link

spikyjt commented Feb 23, 2017

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.

@100000001
Copy link

@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); }); */

@alallier
Copy link
Owner

alallier commented Mar 4, 2017

@spikyjt and @100000001 off the top of my head the only thing I can think of is that reload is being defined too late. For example 404 routes have to be defined last in Express, this is a limitation of Express itself not reload. If you still believe there is a problem can you provide a sample app that I can look it.

@peterwillis
Copy link
Contributor

The way I have middleware setup also makes it difficult for the same reason. I totally understand why you have done it the way you have for the most convenient case. In the middleware chain I have, there is no good place where server and app are available together at a point where the routing can be changed. All the middleware for the app is setup in advance including the error handling and this is a separate module. This module is then required by the serving module, which decides whether it should start an HTTP or HTTPS server for the app. Is it possible to separate out where the route is added so that I can do it in two steps? So I would have to add code in two places for reload to work in this way:

during routing:
reload.configureRoute(app)

then another function that wouldn't need the app:
reload.websocketServer(server)

I think the module would need another way to instantiate so it wasn't always returning the single function. I can put together a PR if you think it is feasible to include it?

@peterwillis
Copy link
Contributor

peterwillis commented Mar 22, 2017

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});

@alallier
Copy link
Owner

@peterwillis I see you are doing server side injection of the reload file. Something we have been wanting to add (issue #12). @peterwillis on your original comment what was going on. A lot of people have been talking about problems like this and we would like to solve it. A provided sample app would be even more helpful.

@peterwillis
Copy link
Contributor

Which point you are asking for a sample for? Would you like to see why it is a problem in my app, or an example of the workaround?

@alallier
Copy link
Owner

@peterwillis I would like to see how it is a problem in your app.

@peterwillis
Copy link
Contributor

@alallier
Copy link
Owner

@peterwillis I moved this to a new issue (#67) since it was something somewhat separate from this issue

@ghost
Copy link

ghost commented Jul 10, 2017

@alallier Is this still an issue?

@alallier
Copy link
Owner

Yeah I re-read this I think it is safe to close given the conversation in this thread. We dopped support for server and just support app now. If for anyone is this thread tries out v2.x and still is having trouble, let me know and I will re-open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants