You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
var fs = require('fs');
|
|
var path = require('path');
|
|
|
|
var express = require('express');
|
|
var morgan = require('morgan')
|
|
var ngn4 = require('ngn4');
|
|
|
|
var config = require('./config.json');
|
|
|
|
var app = express();
|
|
var accessLogStream = fs.createWriteStream(__dirname + '/access.log', {flags: 'a'});
|
|
|
|
app.use(require('compression')());
|
|
app.use(morgan('combined', {stream: accessLogStream}));
|
|
|
|
// Load data
|
|
var set = new ngn4.NameGeneratorSet();
|
|
var dir = path.join(__dirname, 'data');
|
|
fs.readdirSync(dir).forEach(function(file) {
|
|
console.log('Loading ' + file + '...');
|
|
set.import(require('./data/' + file), true);
|
|
});
|
|
|
|
// Prepare merged data file for client to use.
|
|
var data = set.export();
|
|
|
|
// Load scripts
|
|
dir = path.join(__dirname, 'scripts');
|
|
fs.readdirSync(dir).forEach(function(file) {
|
|
console.log('Running ' + file + '...');
|
|
require('./scripts/' + file)(set, app, data);
|
|
});
|
|
|
|
// Prepare static directories
|
|
app.use('/js', express.static('www-root/js'));
|
|
app.use('/css', express.static('www-root/css'));
|
|
app.use('/img/', express.static('www-root/img'));
|
|
|
|
// Set up index
|
|
function sendIndexHtml(req, res) {
|
|
res.header("Content-Type", "text/html; charset=utf-8");
|
|
res.sendFile(path.join(__dirname + '/www-root/index.html'));
|
|
}
|
|
app.get('/index.html', sendIndexHtml);
|
|
app.get('/', sendIndexHtml);
|
|
|
|
var server = app.listen(config.port, function () {
|
|
var host = server.address().address;
|
|
var port = server.address().port;
|
|
console.log('Server listening at http://%s:%s', host, port);
|
|
});
|