annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 var config = require('../configuration');
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 var http = require('http');
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 var files = require('fs').readdirSync('modules/http');
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 var regex = /^mod_.*\.js/;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 var sites = {};
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 for (var i in files) {
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 var file = files[i];
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 if (!regex.test(file))
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 continue;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 var module = require('./http/' + files[i]);
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 for (var j in module) {
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 if (typeof sites[j] != 'undefined')
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 console.log('WARNING: module '+j+' already loaded.');
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 sites[j] = module[j];
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 }
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 }
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 http.createServer(function (req, res) {
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 var sent = false;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 for (var i in sites) {
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 var site = sites[i];
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 if (!site.url.test(req.url))
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 continue;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 sent = site.func(req, res);
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 return;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 }
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 if (!sent) {
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 res.writeHead(404, {'Content-Type': 'text/plain'});
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 res.end('Error 404');
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 }
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 }).listen(8484);