Mercurial > psgxs
comparison 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 |
comparison
equal
deleted
inserted
replaced
32:8735fc6f6f53 | 33:62cbb1c49bc5 |
---|---|
1 var config = require('../configuration'); | |
2 var http = require('http'); | |
3 | |
4 var files = require('fs').readdirSync('modules/http'); | |
5 var regex = /^mod_.*\.js/; | |
6 | |
7 var sites = {}; | |
8 | |
9 for (var i in files) { | |
10 var file = files[i]; | |
11 if (!regex.test(file)) | |
12 continue; | |
13 | |
14 var module = require('./http/' + files[i]); | |
15 for (var j in module) { | |
16 if (typeof sites[j] != 'undefined') | |
17 console.log('WARNING: module '+j+' already loaded.'); | |
18 | |
19 sites[j] = module[j]; | |
20 } | |
21 } | |
22 | |
23 http.createServer(function (req, res) { | |
24 var sent = false; | |
25 for (var i in sites) { | |
26 var site = sites[i]; | |
27 if (!site.url.test(req.url)) | |
28 continue; | |
29 | |
30 sent = site.func(req, res); | |
31 return; | |
32 } | |
33 if (!sent) { | |
34 res.writeHead(404, {'Content-Type': 'text/plain'}); | |
35 res.end('Error 404'); | |
36 } | |
37 }).listen(8484); |