Mercurial > psgxs
view modules/mod_http.js @ 36:26eb015a7c40
Really should learn that “hg addremove” is good.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 10 Nov 2010 01:43:25 +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);