aboutsummaryrefslogtreecommitdiffstats
path: root/mascara/server
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-04-05 13:45:39 +0800
committerkumavis <aaron@kumavis.me>2017-04-05 13:45:39 +0800
commit0cfad78f5decbce04a7fa56e8f80e4fcecd12a79 (patch)
tree79c9198d5ad9db830233c2550eb73ed5e3793460 /mascara/server
parent8b146663483849cb76219bbf610c9ff6c5add68d (diff)
downloadtangerine-wallet-browser-0cfad78f5decbce04a7fa56e8f80e4fcecd12a79.tar
tangerine-wallet-browser-0cfad78f5decbce04a7fa56e8f80e4fcecd12a79.tar.gz
tangerine-wallet-browser-0cfad78f5decbce04a7fa56e8f80e4fcecd12a79.tar.bz2
tangerine-wallet-browser-0cfad78f5decbce04a7fa56e8f80e4fcecd12a79.tar.lz
tangerine-wallet-browser-0cfad78f5decbce04a7fa56e8f80e4fcecd12a79.tar.xz
tangerine-wallet-browser-0cfad78f5decbce04a7fa56e8f80e4fcecd12a79.tar.zst
tangerine-wallet-browser-0cfad78f5decbce04a7fa56e8f80e4fcecd12a79.zip
mascara - rename things + break out mascara asset server
Diffstat (limited to 'mascara/server')
-rw-r--r--mascara/server/index.html20
-rw-r--r--mascara/server/index.js32
-rw-r--r--mascara/server/util.js45
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()
+ })
+ }
+
+}