admin page now loads properly

This commit is contained in:
AJ ONeal 2017-04-27 16:50:03 -06:00
parent 58a0b592ff
commit 4b470ffe51
4 changed files with 44 additions and 6 deletions

View File

@ -86,6 +86,36 @@ function readConfigAndRun(args) {
config.cwd = process.cwd();
}
var ipaddr = require('ipaddr.js');
var addresses = [];
var ifaces = require('../lib/local-ip.js').find();
Object.keys(ifaces).forEach(function (ifacename) {
var iface = ifaces[ifacename];
iface.ipv4.forEach(function (ip) {
addresses.push(ip);
});
iface.ipv6.forEach(function (ip) {
addresses.push(ip);
});
});
addresses.sort(function (a, b) {
if (a.family !== b.family) {
return 'IPv4' === a.family ? 1 : -1;
}
return a.address > b.address ? 1 : -1;
});
addresses.forEach(function (addr) {
addr.range = ipaddr.parse(addr.address).range();
});
// TODO maybe move to config.state.addresses (?)
config.addresses = addresses;
config.device = { hostname: 'TODO: fetch hostname from device and from ip and try to make a match' };
if (config.tcp.ports) {
run(config);
return;

View File

@ -1,6 +1,6 @@
'use strict';
module.exports = function (deps, conf) {
module.exports = function (deps, conf, overrideHttp) {
var express = require('express');
//var finalhandler = require('finalhandler');
var serveStatic = require('serve-static');
@ -244,7 +244,13 @@ module.exports = function (deps, conf) {
}
};
var opts = conf.http;
var opts = overrideHttp || conf.http;
if (!opts.defaults) {
opts.defaults = {};
}
if (!opts.global) {
opts.global = {};
}
if (!opts.sites) {
opts.sites = [];
}

View File

@ -5,9 +5,10 @@ module.exports.create = function (deps, conf) {
//var defaultServername = 'localhost.daplie.me';
//var defaultWebRoot = '.';
var assetsPath = path.join(__dirname, '..', '..', 'packages', 'assets');
var opts = /*conf.http ||*/ {};
var opts = {};
opts.sites = [];
opts.global = opts.global || {};
opts.sites = opts.sites || [];
opts.sites._map = {};
// argv.sites
@ -58,7 +59,8 @@ module.exports.create = function (deps, conf) {
]
});
var app = require('../app.js')(deps, { cwd: conf.cwd, http: opts });
/* device, addresses, cwd, http */
var app = require('../app.js')(deps, conf, opts);
var http = require('http');
return http.createServer(app);
};

View File

@ -139,7 +139,7 @@ module.exports.create = function (deps, conf) {
isAuthorized(req, res, function () {
if ('POST' !== req.method) {
res.setHeader('Content-Type', 'application/json;');
res.end(JSON.stringify(deps.recase.snakeCopy(conf.snake_copy)));
res.end(JSON.stringify(deps.recase.snakeCopy(conf)));
return;
}