diff --git a/lib/core/config.js b/lib/core/config.js
index c2f21d55..3aa06488 100644
--- a/lib/core/config.js
+++ b/lib/core/config.js
@@ -309,7 +309,7 @@ Config.prototype.loadCommunicationConfigFile = function() {
Config.prototype.loadWebServerConfigFile = function() {
var configObject = {
- "enabled": true, "host": "localhost", "port": 8000
+ "enabled": true, "host": "localhost", "port": 8000, "enableCatchAll": true
};
let configFilePath = this._getFileOrOject(this.configDir, 'webserver', 'webserver');
diff --git a/lib/core/fs.js b/lib/core/fs.js
index 4e2e2179..87757dc2 100644
--- a/lib/core/fs.js
+++ b/lib/core/fs.js
@@ -91,6 +91,14 @@ function tmpDir() {
return utils.joinPath(os.tmpdir(), ...arguments);
}
+function readdirSync() {
+ return fs.readdirSync.apply(fs.readdirSync, arguments);
+}
+
+function readdir() {
+ return fs.readdir.apply(fs.readdirSync, arguments);
+}
+
module.exports = {
mkdirpSync,
mkdirp,
@@ -111,5 +119,7 @@ module.exports = {
embarkPath,
dappPath,
createWriteStream,
- tmpDir
+ tmpDir,
+ readdirSync,
+ readdir
};
diff --git a/lib/core/plugin.js b/lib/core/plugin.js
index 86edefd6..9ea3df52 100644
--- a/lib/core/plugin.js
+++ b/lib/core/plugin.js
@@ -208,7 +208,7 @@ Plugin.prototype.registerActionForEvent = function(eventName, cb) {
Plugin.prototype.registerAPICall = function(method, endpoint, cb) {
console.dir("registerAPICall " + method + " " + endpoint);
this.apiCalls.push({method: method, endpoint: endpoint, cb: cb});
- this.pluginTypes.push('apiCalls');
+ this.addPluginType('apiCalls');
};
Plugin.prototype.runFilePipeline = function() {
diff --git a/lib/modules/webserver/backend/assets/images/dade.jpg b/lib/modules/webserver/backend/assets/images/dade.jpg
new file mode 100644
index 00000000..c41b2142
Binary files /dev/null and b/lib/modules/webserver/backend/assets/images/dade.jpg differ
diff --git a/lib/modules/webserver/backend/contracts/view.html b/lib/modules/webserver/backend/contracts/view.html
index 3b899f2a..ac8223fb 100644
--- a/lib/modules/webserver/backend/contracts/view.html
+++ b/lib/modules/webserver/backend/contracts/view.html
@@ -112,7 +112,7 @@
-
+
Dade Murphy
@@ -261,21 +261,21 @@
if (contract.deploy === false) {
$tr.append(
- $(`${contract.name}`),
+ $(` | ${contract.className}`),
$(' | ').text('Interface or set to not deploy'),
$(' | ').text('n/a'),
);
} else if (contract.error) {
$tr.append(
- $(` | ${contract.name}`),
+ $(` | ${contract.className}`),
$(' | ').text((contract.error).split("\n")[0].replace(/Error: /g, '').substring(0, 32)),
$(' | ').text('Error'),
);
} else {
$tr.append(
- $(` | ${contract.name}`),
- $(' | ').text(contract.address || '...'),
- $(' | ').text(contract.address !== undefined ? 'Deployed' : 'Pending')
+ $(` | ${contract.className}`),
+ $(' | ').text(contract.deployedAddress || '...'),
+ $(' | ').text(contract.deployedAddress !== undefined ? 'Deployed' : 'Pending')
);
}
diff --git a/lib/modules/webserver/index.js b/lib/modules/webserver/index.js
index 3a343f96..be4f517f 100644
--- a/lib/modules/webserver/index.js
+++ b/lib/modules/webserver/index.js
@@ -15,10 +15,11 @@ class WebServer {
this.host = options.host || this.webServerConfig.host;
this.port = options.port || this.webServerConfig.port;
+ this.enableCatchAll = this.webServerConfig.enableCatchAll === true;
this.events.emit("status", __("Starting Server"));
//this.server = new Server({logger: this.logger, host: this.host, port: this.port, events: this.events});
- this.server = new Server({logger: this.logger, host: this.host, port: this.port, events: this.events, plugins: this.plugins});
+ this.server = new Server({logger: this.logger, host: this.host, port: this.port, events: this.events, plugins: this.plugins, enableCatchAll: this.enableCatchAll});
this.setServiceCheck();
this.listenToCommands();
diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js
index c437bd0c..e4c4fb79 100644
--- a/lib/modules/webserver/server.js
+++ b/lib/modules/webserver/server.js
@@ -1,11 +1,8 @@
-let finalhandler = require('finalhandler');
-let http = require('http');
-let serveStatic = require('serve-static');
require('http-shutdown').extend();
-var express = require('express');
-let path = require('path');
-var expressWebSocket = require('express-ws');
-var bodyParser = require('body-parser');
+const express = require('express');
+const path = require('path');
+const expressWebSocket = require('express-ws');
+const bodyParser = require('body-parser');
const fs = require('../../core/fs');
class Server {
@@ -16,6 +13,7 @@ class Server {
this.hostname = options.host || 'localhost';
this.logger = options.logger;
this.plugins = options.plugins;
+ this.enableCatchAll = options.enableCatchAll;
}
start(callback) {
@@ -27,51 +25,49 @@ class Server {
}
return;
}
- let serve = serveStatic(this.dist, {'index': ['index.html', 'index.htm']});
var app = express();
app.use(serve);
//app.use('/embark', serveStatic(path.join(__dirname, 'backend'), {'backend': ['index.html', 'index.htm']}));
//app.use('/backend', serveStatic(path.join(__dirname, 'backend'), {'backend': ['index.html', 'index.htm']}));
- app.get('/embark', function (req, res) {
- res.sendFile(path.join(__dirname, 'backend', 'index.html'));
- });
+ //app.get('/embark', function (req, res) {
+ // res.sendFile(path.join(__dirname, 'backend', 'index.html'));
+ //});
- app.use(bodyParser.json()); // support json encoded bodies
- app.use(bodyParser.urlencoded({extended: true})); // support encoded bodies
+ // support static files
+ app.use(express.static(path.join(fs.dappPath(this.dist)), {'index': ['index.html', 'index.htm']}));
+ app.use(['/embark', '/backend', '/admin'], express.static(path.join(__dirname, 'backend'), {'index': ['index.html', 'index.htm']})); // mount the sub app
+ // support json encoded bodies
+ app.use(bodyParser.json());
+
+ // support encoded bodies
+ app.use(bodyParser.urlencoded({extended: true}));
+
+ // support websockets
expressWebSocket(app);
if (self.plugins){
let apiCalls = self.plugins.getPluginsProperty("apiCalls", "apiCalls");
for (let apiCall of apiCalls) {
- app[apiCall.method].apply(app, [apiCall.endpoint, apiCall.cb]);
+ app[apiCall.method](apiCall.endpoint, apiCall.cb);
+ this.logger.trace(`webserver> registered api call ${apiCall.method.toUpperCase()} ${apiCall.endpoint}`);
}
}
- // app.get('/embark', function (req, res) {
- // res.send('Welcome to Embark');
- // });
-
- // support react routes
- // suggested changes from https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#serving-apps-with-client-side-routing
- app.use(express.static(path.join(fs.dappPath(this.dist))));
- app.get('/*', function (req, res) {
- res.sendFile(path.join(fs.dappPath(self.dist, 'index.html')));
- });
+ // catchall to support react routing
+ if(this.enableCatchAll === true){
+ app.get('/*', function (req, res) {
+ self.logger.trace('webserver> GET ' + req.path);
+ res.sendFile(path.join(fs.dappPath(self.dist, 'index.html')));
+ });
+ }
app.listen(this.port);
- //this.logger.info(__("webserver available at") + " " + ("http://" + this.hostname + ":" + this.port).bold.underline.green);
- //this.server.listen(this.port, this.hostname);
+ this.logger.info("webserver available at " + ("http://" + this.hostname + ":" + this.port).bold.underline.green);
- //this.server = http.createServer(function onRequest(req, res) {
- // serve(req, res, finalhandler(req, res));
- //}).withShutdown();
-
- //this.logger.info("webserver available at " + ("http://" + this.hostname + ":" + this.port).bold.underline.green);
- //this.server.listen(this.port, this.hostname);
if (callback) {
callback();
}
|