Skip to content

Instantly share code, notes, and snippets.

@lsm
Last active July 14, 2016 18:59
Show Gist options
  • Save lsm/ee2e2a71bb4de97db7896811587e012b to your computer and use it in GitHub Desktop.
Save lsm/ee2e2a71bb4de97db7896811587e012b to your computer and use it in GitHub Desktop.
express -> micromono
var app = require('express')()
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'pug')
app.use(express.static(path.join(__dirname, 'public')))
app.get('/', function(req, res){
res.render('index.pug')
})
app.listen(3000)
var micromono = require('micromono')
var Service = micromono.createService({
init: [function(app){
// `app` here is a built-in dependency which is a express instance.
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'pug')
app.use(express.static(path.join(__dirname, 'public')))
}, ['app']], // This is the format for getting dependencies
// There are other dependencies like
// `service` - instance of current service
// `chnAdapter` - instance of socketmq for channel
route: {
'/': function(req, res){
res.render('index.pug')
}
}
})
// Service is designed to run behind a `balancer` so it by default listen on a random port for http requests.
// To change this you can set the environment variable `PORT`:
process.env.PORT = 3000
micromono.startService(Service)
// Now this version is totally equivalent to the express version above
Copy link

ghost commented Jul 14, 2016

Does the balancer work by listening to the main website address then distributing the http requests to servers behind it listening to known random http ports?

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