Mercurial > psgxs
diff modules/mod_http.js @ 33:62cbb1c49bc5
Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 05 Nov 2010 14:01:45 +0100 |
parents | |
children | bc717575e66a |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/modules/mod_http.js @@ -0,0 +1,37 @@ +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);