Files
NodeBB/install/web.js

55 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-04-21 14:32:21 -04:00
"use strict";
2015-04-21 14:52:57 -04:00
var winston = require('winston'),
express = require('express'),
2015-04-21 16:21:04 -04:00
fs = require('fs'),
2015-04-21 14:52:57 -04:00
path = require('path'),
2015-04-21 16:21:04 -04:00
less = require('less'),
2015-04-21 14:52:57 -04:00
app = express();
2015-04-21 14:32:21 -04:00
var web = {};
2015-04-21 14:52:57 -04:00
web.install = function(port) {
port = port || 8080;
winston.info('Launching web installer on port ', port);
2015-04-21 14:32:21 -04:00
2015-04-21 16:21:04 -04:00
compileLess(function() {
setupRoutes();
launchExpress(port);
});
2015-04-21 14:32:21 -04:00
};
2015-04-21 14:52:57 -04:00
function launchExpress(port) {
app.use(express.static('public', {}));
app.engine('tpl', require('templates.js').__express);
app.set('view engine', 'tpl');
app.set('views', path.join(__dirname, '../src/views'));
var server = app.listen(port, function() {
var host = server.address().address;
winston.info('Web installer listening on http://%s:%s', host, port);
});
}
function setupRoutes() {
app.get('/', install);
}
function install(req, res, next) {
res.render('install/index', {});
}
2015-04-21 16:21:04 -04:00
function compileLess(callback) {
fs.readFile(path.join(__dirname, '../public/less/install.less'), function(err, style) {
less.render(style.toString(), function(err, css) {
if(err) {
return winston.error('Unable to compile LESS: ', err);
}
fs.writeFile(path.join(__dirname, '../public/stylesheet.css'), css.css, callback);
});
});
}
2015-04-21 14:32:21 -04:00
module.exports = web;