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

Remote Usage #71

Closed
Shadeslayer345 opened this issue Mar 27, 2016 · 5 comments
Closed

Remote Usage #71

Shadeslayer345 opened this issue Mar 27, 2016 · 5 comments

Comments

@Shadeslayer345
Copy link

I've recently started using jspm again with hot-reloading and it's been great. One thing I'm not sure how to do efficiently is remote testing. When using the default loader, since localhost is used, there is no hot reloading on a remote system that's accessing the server, right now I simply set my dev machine's ip and everything works fine

import hr from 'systemjs-hot-reloader';
import module from './modules.js';

...

new hr('http://138.238.148.14:2368');

export function __reload(m) {
  if (m.component.state)
    module.setState('m.component.state');
}

is there another way to achieve this without having to set the ip address every time?

@Shadeslayer345 Shadeslayer345 changed the title Remote Testing Remote Usage Mar 27, 2016
@Shadeslayer345
Copy link
Author

I've made a slight improvement using the ip module:

I'm using express to render jade so I simple pass the ip address to the jade template

import ip from 'ip';
...

app.get(`/`, (req, res) => {
  if (process.env.NODE_ENV === `production`) {
    res.render(`index.js`, {production: false});
  } else {
    res.render(`index.js`, {production: true, address: `${ip.address()}`});
  }
})

And it enables the hot-reloader

if (prod)
  script(type='text/javascript').
    SystemJS.import('./app.js');
else
  script(type='text/javascript').
    System.import('systemjs-hot-reloader').then(function(hr){
      new hr.default('http://#{address}:8090');
    });
    System.import('./app.js')

I'd love to see any other solutions anyone has

@npbenjohnson
Copy link
Contributor

npbenjohnson commented Apr 21, 2016

This probably isn't bulletproof but it should work generally:
window.location.href.match(/([^\/]//[^:\/?])([:/?]|$)/)[1] + ':8090'

window.location.href.match(/([^\/]*\/\/[^/:?]*)/)[1] + ':8090'

I have no idea why I thought that first one worked.

@svi3c
Copy link

svi3c commented Jun 1, 2016

I'm suggest using something like this:

new hr.default("//" + location.hostname + ":8090");

@born2net
Copy link

born2net commented Jun 1, 2016

my take:

 <script>
     switch (location.port){
        case '9089': {
          // alert('mode: hot-reload 9089');
          var readyForMainLoad
          if (location.origin.match(/localhost/)) {
             System.trace = true
             readyForMainLoad = System.import('systemjs-hot-reloader').then(function(HotReloader){
                window.hr = new HotReloader.default('http://localhost:9089')
             })
          }
          Promise.resolve(readyForMainLoad).then(() => {
             System.import('reflect-metadata')
             .then(function(){System.import('zone.js')})
             .then(function(){System.import('../App')})
            })
          break;
        }
        default: {
          // alert('mode: watch port 8080');
          System.import('../App')
             .catch(function (e) {
                console.error(e,
                  'error system.js ' + e);
             });
          break;
        }
     }
  </script>

@alexisvincent
Copy link
Owner

Would be achieved via connect("//" + location.hostname + ":8090")

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

5 participants