Skip to content

Commit

Permalink
doc: document new option "loc" for using an existing http server
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed Jun 11, 2019
1 parent 5d3732a commit baa5ad4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@ browser.pipe(process.stdout);
browser.write('console.log(window.location.href);');
browser.write('window.close();');
browser.end();
```

Alternatively, use an existing http server. Note you cannot write to electron-stream when outside http server is in use.

```js
var electron = require('electron-stream');
var http = require('http');

var server = http.createServer((req, res) => {
if (/^\/bundle\.js/.test(req.url)) {
res.setHeader('content-type', 'application/javascript');
res.setHeader('cache-control', 'no-cache');
res.end('console.log("hello");window.close();');
return;
}

if (req.url == '/') {
res.setHeader('Content-Type', 'text/html');
res.end(`<!DOCTYPE html><meta charset="utf8"><body><script src="/bundle.js"></script></body>`);
return;
}
});

server.listen(8000);
var browser = electron({ loc: 'http://localhost:8000' });
browser.pipe(process.stdout);
browser.end();

```

## Output streams
Expand Down Expand Up @@ -82,6 +110,7 @@ Options:
- `node`: Enable node integration. Defaults to `false`.
- `basedir`: Set this if you need to require node modules in `node` mode
- `static`: Serve static files from this directory at `/`
- `loc`: a full url like `http://localhost:8080/` for using an existing http server. When `loc` is supplied, options `node`, `basedir`, and `static` are all ignored.

### electron#stdout
### electron#stderr
Expand Down
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ Electron.prototype._onfinish = function(){
if (this.killed) return;
this.source.push(null);

// When browser-run runs electron-stream,
// use the server booted by browser-run,
// instead of creating new one in _createSourceUrl.
// Use existing http(s) server with {loc: 'http://url'},
// this skips creating inner http server in _createSourceUrl.
if (this.opts.loc) {
return cb(this.opts.loc);
}
Expand Down

0 comments on commit baa5ad4

Please sign in to comment.