Last active
July 14, 2016 18:59
-
-
Save lsm/ee2e2a71bb4de97db7896811587e012b to your computer and use it in GitHub Desktop.
express -> micromono
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?