Skip to content

Instantly share code, notes, and snippets.

@imalberto
Last active August 29, 2015 13:56
Show Gist options
  • Save imalberto/8832217 to your computer and use it in GitHub Desktop.
Save imalberto/8832217 to your computer and use it in GitHub Desktop.
sample app.js
'use strict';
var debug = require('debug')('app'),
express = require('express'),
libmojito = require('../../../'),
app,
mojito;
app = express();
app.set('port', process.env.PORT || 8666);
libmojito.extend(app);
app.use(libmojito.middleware());
app.mojito.attachRoutes();
app.post('/tunnel', libmojito.tunnelMiddleware());
app.get('/:type/:action', function (req, res, next) {
libmojito.dispatch(req.params.type + '.' + req.params.action)(req, res, next);
});
app.get('/status', function (req, res) {
res.send('200 OK');
});
app.listen(app.get('port'), function () {
debug('Server listening on port ' + app.get('port') + ' ' +
'in ' + app.get('env') + ' mode');
});
function dispatch (call) {
return function (req, res, next) {
// do it here
// replace req.params with keys that matches {key} from call
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment