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

Server lifecycle events? #49

Closed
Whoaa512 opened this issue Mar 22, 2019 · 1 comment
Closed

Server lifecycle events? #49

Whoaa512 opened this issue Mar 22, 2019 · 1 comment

Comments

@Whoaa512
Copy link

Whoaa512 commented Mar 22, 2019

My use case here is that in dev mode I'd like to be able to run:

var openBrowser = require('react-dev-utils/openBrowser')

if (openBrowser('http://localhost:3000')) {
  console.log('The browser tab has been opened!');
}

after the server has created the manifest.

Essentially I'm looking for some sort of lifecycle hooks or events to run code before or after.

@Whoaa512 Whoaa512 changed the title No way to run code on server start Server lifecycle events? Mar 22, 2019
@asadm
Copy link
Contributor

asadm commented Mar 27, 2019

I think the only way to do this is by using zero from it's API. It returns a promise after which you can do additional stuff.

This example will run zero in ./www/ directory:

const path = require("path");
const startServer = require("zero").server;
const openBrowser = require('react-dev-utils/openBrowser');


startServer(path.join(__dirname, "./www")).then(()=>{
  if (openBrowser('http://localhost:3000')) {
    console.log('The browser tab has been opened!');
  }
})

@asadm asadm closed this as completed Aug 16, 2019
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

2 participants