-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.js
44 lines (35 loc) · 1.1 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Serverwide configuration
// (c)copyright 2014 by Gerald Wodni <[email protected]>
"use strict";
var fs = require("fs");
function Config( opts ) {
var configData = null;
/* dynamic-config (depends on request) */
function dynamicConfig( req, res, next ) {
/* TODO: check real config for debug-hosts */
req.config.debugHost = true;
next();
};
/* config-callback */
return function( req, res, next ) {
console.log( "CONFIG!" );
/* if config loaded, add it to request and resume */
if( configData ) {
req.config = configData;
dynamicConfig( req, res, next );
return;
}
/* otherwise attempt to run config */
fs.readFile( "config.json", 'utf8', function( err, data ) {
if( !err ) {
/* load static config */
configData = JSON.parse( data );
dynamicConfig( req, res, next );
}
else
/* on error just resume */
next();
});
};
}
module.exports = Config;