Skip to content

Commit

Permalink
Allow plugins to contain client scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
martindale committed Aug 3, 2015
1 parent 91406a2 commit 74398b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/Service/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var Service = require('./index');
var WebSocketServer = require('maki-service-websockets');
var express = require('express');

var fs = require('fs');
var pem = require('pem');
var async = require('async');
var _ = require('lodash');
Expand All @@ -11,12 +12,15 @@ var streamifier = require('streamifier');
var Torrent = require('node-torrent-stream');
var ObjectID = require('mongoose').Types.ObjectId;

var Bundler = require('browserify');

var HTTP = function() {
this.maki = null;
this.name = 'http';
this._pre = {};
this._post = {};
this._plugins = [];
this._scripts = [];
};

require('util').inherits( HTTP , Service );
Expand Down Expand Up @@ -279,8 +283,11 @@ HTTP.prototype.attach = function( maki ) {
maki.app.locals[ 'services' ] = maki.services;

self._plugins.forEach(function(plugin) {
if (self.debug) console.log('iterating plugin:', plugin);

if (plugin.setup) plugin.setup( maki );
if (plugin.middleware) maki.app.use( plugin.middleware );
if (plugin.client) self._scripts.push( plugin.client );
});

maki.app.use(function(req, res, next) {
Expand Down Expand Up @@ -752,6 +759,18 @@ HTTP.prototype.start = function( started ) {

if (!started) var started = new Function();

var browserify = new Bundler();
self._scripts.forEach(function(s) {
browserify.add(s);
});

var bundlePath = __dirname + '/../../public/js/bundle.js';
var bundle = fs.createWriteStream(bundlePath);
bundle.on('open', function() {
browserify.bundle().pipe(bundle);
});


// TODO: spdy/https should be the default. Make it so, with optional http.
// TODO: allow configurable certificate, supplied by config
// this will allow for standalone mode, as well as a "backend worker" mode.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"async": "~0.7.0",
"body-parser": "~1.2.2",
"browserify": "^11.0.1",
"coalescent": "^0.5.0-alpha.3",
"colors": "^1.0.3",
"connect-busboy": "0.0.2",
Expand Down

0 comments on commit 74398b0

Please sign in to comment.