Orane Orane - 1 month ago 9
Node.js Question

Express with Browser-Sync

I want to integrate BrowserSync with express.

I want to pull a URL from the DB and use it as the proxy. However the setup I've come up with initializes a new BrowserSync server for each request.

Is there a way to accomplish this without initializing a new BrowserSync server every time?

Or should I be using another approach?

var bs = require("browser-sync");
var express = require("express");

var router = express.Router();
var app = express();

router.get("/", function(req, res){
notify: false,
open: false,
ui: false,
port: 10000,
proxy: 'http://example.com'


app.listen(8080, function(){
console.log('listening on *:8080');


So it turns out this cant actually be done with any ease.

I ended up using express-http-proxy instead and express-vhost for subdomains.

app = require('express')();
vhost = require('vhost');
proxy = require('express-http-proxy');

app.use(vhost('sub1.mysite.com', proxy('http://www.example.com')));


Hopefully this helps someone one day.