Setup structure, dynamic routing from config.json
This commit is contained in:
@ -4,9 +4,20 @@ var url = require('url');
|
||||
var mime = require('mime');
|
||||
var io = require('socket.io');
|
||||
|
||||
var urlMapping = [];
|
||||
var config = require('../config.json');
|
||||
|
||||
exports.start = function(ip, port, callback) {
|
||||
exports.start = function(callback) {
|
||||
var urlMapping = [];
|
||||
var routeKeys = Object.keys(config.routes);
|
||||
|
||||
// Map the (static) routes from our config.
|
||||
for (var i = 0; i < routeKeys.length; i++) {
|
||||
urlMapping[routeKeys[i]] = config.routes[routeKeys[i]];
|
||||
}
|
||||
|
||||
console.log(Object.keys(config.routes));
|
||||
|
||||
// Create our tiny little HTTP server.
|
||||
var server = http.createServer(function(req, res) {
|
||||
var requestUrl = url.parse(req.url).pathname;
|
||||
|
||||
@ -24,13 +35,13 @@ exports.start = function(ip, port, callback) {
|
||||
}
|
||||
});
|
||||
|
||||
server.listen(port, ip);
|
||||
server.listen(config.site.port, config.site.ip);
|
||||
|
||||
// I don't like this. But it works, I think.
|
||||
exports.io = (io = io.listen(server));
|
||||
|
||||
// Since everything is loaded, do some final prep work.
|
||||
callback();
|
||||
};
|
||||
console.log('Started on %s:%d', config.site.ip, config.site.port);
|
||||
|
||||
exports.urlMapping = urlMapping;
|
||||
callback();
|
||||
};
|
Reference in New Issue
Block a user