Skip to content

Instantly share code, notes, and snippets.

@lsm
Last active Jul 14, 2016
Embed
What would you like to do?
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
@ghost

This comment has been minimized.

Copy link

@ghost 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