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

Feature request - Automatically inject reload script in HTML responses #149

Closed
hrastnik opened this issue Jan 29, 2018 · 1 comment
Closed

Comments

@hrastnik
Copy link

hrastnik commented Jan 29, 2018

When using reload with express, instead of having to manually add the <script> tag, it could be injected automatically by intercepting the response and overwriting the response data.

I've used this code in my server and it seems to work...

reload(app);
app.use(function(req, res, next) {
  const send = res.send;

  res.send = function() {
    if (typeof arguments[0] === "string") {
      arguments[0] = arguments[0].replace(
        "</html>",
        '<script src="/reload/reload.js"></script></html>'
      );
    }
    return send.apply(res, arguments);
  };

  next();
});
@hrastnik hrastnik changed the title Feature request Feature request - Automatically inject reload script in HTML responses Jan 29, 2018
@alallier
Copy link
Owner

Closing duplicate of #12. But I don't see why we can't add this as an option to reload.

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

No branches or pull requests

2 participants