Skip to content

Commit

Permalink
[dist] [misc] Added more examples
Browse files Browse the repository at this point in the history
  * Removes errant comment
  * Update .gitignore with nyc folders
  • Loading branch information
Marak committed Sep 19, 2017
1 parent f0075c4 commit 1f89318
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,5 +1,7 @@
.DS_Store
node_modules/
reports/
__pycache__/
*.pyc
*.pyo
.nyc_output
22 changes: 22 additions & 0 deletions examples/express-jail-chroot.js
@@ -0,0 +1,22 @@
var microcule = require('../');
var express = require('express');
var app = express();

var nodeService = function testService (opts) {
var res = opts.res;
console.log('logging to console');
res.end('ran service');
};

var handler = microcule.plugins.spawn({
code: nodeService,
language: "javascript",
jail: "chroot",
jailArgs: [ '/Users/worker']
});

app.use(handler);

app.listen(3000, function () {
console.log('server started on port 3000');
});
45 changes: 45 additions & 0 deletions examples/express-jail-nsjail.js
@@ -0,0 +1,45 @@
var microcule = require('../');
var express = require('express');
var app = express();

var nodeService = function testService (opts) {
var res = opts.res;
console.log('logging to console');
setTimeout(function(){
res.end('ran service');
}, 10)
};

var bash = microcule.plugins.spawn({
code: 'ps -ax',
language: "bash",
jail: "nsjail",
jailArgs: [ '-Mo', '--chroot', '/var/chroot/', '--user', '99999', '--group', '99999']
});

var handler = microcule.plugins.spawn({
code: nodeService,
language: "javascript",
jail: "nsjail",
jailArgs: [ '-Mo', '--chroot', '/var/chroot/', '--user', '99999', '--group', '99999']
});

var ps = microcule.plugins.spawn({
bin: "/bin/ps",
argv: ['-ax' ]
});

var psJail = microcule.plugins.spawn({
bin: "/bin/ps",
argv: ['-ax' ],
jail: "nsjail",
jailArgs: [ '-Mo', '--chroot', '/var/chroot/', '--user', '99999', '--group', '99999']
});

app.use('/node', handler);
app.use('/ps', ps);
app.use('/psjail', psJail);

app.listen(3000, function () {
console.log('server started on port 3000');
});
44 changes: 44 additions & 0 deletions examples/express-service-view.js
@@ -0,0 +1,44 @@
var microcule = require('../');
var express = require('express');
var app = express();

var nodeService = function testService (opts) {
var res = opts.res;
console.log('logging to console');
res.end('Hello world!');
};

var handler = microcule.plugins.spawn({
code: nodeService,
language: "javascript"
});

//var view = microcule.plugins.viewPresenter({}, req, res, next);

app.use('/view', function(req, res, next){
microcule.viewPresenter({
view: "Service outputs: {{hook.output}}"
}, req, res, function(err, req, output){
handler(req, output, next)
})
});

/* presenter API has been removed ( for now )
app.use('/view-presenter', function(req, res, next){
microcule.viewPresenter({
view: "Service outputs: {{hook.output}} <div class='output'><div>",
presenter: function (opts, cb) {
opts.res.setHeader('Content-type', 'text/html');
var $ = this.$;
$('.output').html('presenters can use $ selectors');
cb(null, $.html());
}
}, req, res, function(err, req, output){
handler(req, output, next)
})
});
*/

app.listen(3000, function () {
console.log('server started on port 3000');
});
7 changes: 7 additions & 0 deletions examples/services/echo/echoOld.js
@@ -0,0 +1,7 @@
module.exports = function (hook) {
var req = hook.req, res = hook.res;
res.write('Hello, this is a JavaScript function.\n');
res.write('hook.params is populated with request parameters\n');
res.write(JSON.stringify(req.params, true, 2));
res.end('');
};
1 change: 1 addition & 0 deletions examples/services/hello-world/hello.lua
@@ -0,0 +1 @@
print ("hello world")
1 change: 1 addition & 0 deletions test/fixtures/invalid-services/ReadMe.md
@@ -0,0 +1 @@
Collection of invalid / erroring microservices. Useful for testing error conditions, can be put into unit tests.
1 change: 0 additions & 1 deletion test/plugin-tests.js
Expand Up @@ -51,7 +51,6 @@ test('attempt to send simple http request to running microservice', function (t)
method: "GET",
json: true
}, function (err, res, body) {
console.log("bbb", body)
t.equal(typeof body, "object", 'got correct response');
//t.equal(body, "b", "echo'd back property")
t.end();
Expand Down

0 comments on commit 1f89318

Please sign in to comment.