view modules/mod_http.js @ 39:4c808bfe0658

Various little fixes.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 15 Dec 2010 22:22:14 +0100
parents 62cbb1c49bc5
children bc717575e66a
line wrap: on
line source

var config = require('../configuration');
var http = require('http');

var files = require('fs').readdirSync('modules/http');
var regex = /^mod_.*\.js/;

var sites = {};

for (var i in files) {
	var file = files[i];
	if (!regex.test(file))
		continue;

	var module = require('./http/' + files[i]);
	for (var j in module) {
		if (typeof sites[j] != 'undefined')
			console.log('WARNING: module '+j+' already loaded.');

		sites[j] = module[j];
	}
}

http.createServer(function (req, res) {
	var sent = false;
	for (var i in sites) {
		var site = sites[i];
		if (!site.url.test(req.url))
			continue;

		sent = site.func(req, res);
		return;
	}
	if (!sent) {
		res.writeHead(404, {'Content-Type': 'text/plain'});
		res.end('Error 404');
	}
}).listen(8484);