diff options
mascara - rename things + break out mascara asset server
Diffstat (limited to 'mascara/server')
-rw-r--r-- | mascara/server/index.html | 20 | ||||
-rw-r--r-- | mascara/server/index.js | 32 | ||||
-rw-r--r-- | mascara/server/util.js | 45 |
3 files changed, 77 insertions, 20 deletions
diff --git a/mascara/server/index.html b/mascara/server/index.html deleted file mode 100644 index 2308dd98b..000000000 --- a/mascara/server/index.html +++ /dev/null @@ -1,20 +0,0 @@ -<!doctype html> - -<html lang="en"> -<head> - <meta charset="utf-8"> - - <title>MetaMask ZeroClient Iframe</title> - <meta name="description" content="MetaMask ZeroClient"> - <meta name="author" content="MetaMask"> - - <!--[if lt IE 9]> - <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> - <![endif]--> -</head> - -<body> - Hello! I am the MetaMask iframe. - <script src="/controller.js"></script> -</body> -</html>
\ No newline at end of file diff --git a/mascara/server/index.js b/mascara/server/index.js new file mode 100644 index 000000000..61dc61a02 --- /dev/null +++ b/mascara/server/index.js @@ -0,0 +1,32 @@ +const express = require('express') +const createBundle = require('./util').createBundle +const serveBundle = require('./util').serveBundle + +module.exports = createMetamascaraServer + + +function createMetamascaraServer(){ + + // start bundlers + const metamascaraBundle = createBundle('./src/mascara.js') + const proxyBundle = createBundle('./src/proxy.js') + const uiBundle = createBundle('./src/popup.js') + const backgroundBuild = createBundle('./src/background.js') + + // serve bundles + const server = express() + // ui window + serveBundle(server, '/ui.js', uiBundle) + server.use(express.static(__dirname+'/../ui/')) + server.use(express.static(__dirname+'/../../dist/chrome')) + // metamascara + serveBundle(server, '/metamascara.js', metamascaraBundle) + // proxy + serveBundle(server, '/proxy/proxy.js', proxyBundle) + server.use('/proxy/', express.static(__dirname+'/../proxy')) + // background + serveBundle(server, '/background.js', backgroundBuild) + + return server + +} diff --git a/mascara/server/util.js b/mascara/server/util.js new file mode 100644 index 000000000..6e25b35d8 --- /dev/null +++ b/mascara/server/util.js @@ -0,0 +1,45 @@ +const browserify = require('browserify') +const watchify = require('watchify') + +module.exports = { + serveBundle, + createBundle, +} + + +function serveBundle(server, path, bundle){ + server.get(path, function(req, res){ + res.setHeader('Content-Type', 'application/javascript; charset=UTF-8') + res.send(bundle.latest) + }) +} + +function createBundle(entryPoint){ + + var bundleContainer = {} + + var bundler = browserify({ + entries: [entryPoint], + cache: {}, + packageCache: {}, + plugin: [watchify], + }) + + bundler.on('update', bundle) + bundle() + + return bundleContainer + + function bundle() { + bundler.bundle(function(err, result){ + if (err) { + console.log(`Bundle failed! (${entryPoint})`) + console.error(err) + return + } + console.log(`Bundle updated! (${entryPoint})`) + bundleContainer.latest = result.toString() + }) + } + +} |