Skip to content
This repository has been archived by the owner on Sep 13, 2018. It is now read-only.

Commit

Permalink
changed the way configuration is done: it now include the port on wic…
Browse files Browse the repository at this point in the history
…h to run the server
  • Loading branch information
fgascon committed Nov 29, 2012
1 parent eda104b commit a16c90c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 5 additions & 3 deletions bin/server
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node

var config = require("nconf").loadFilesSync([__dirname+"/../config.json"]);
var config = require("nconf")
.argv()
.file({file:__dirname+"/../config.json"});

redirect = require('../lib/redirect')(config, 3000);
console.log('redirect running on port 3000');
redirect = require('../lib/redirect')(config.get('redirects'), config.get('port'));
console.log('redirect running on port %d', redirect.address().port);
7 changes: 5 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"code": 302,
"host": "http://pksunkara.github.com"
"port": 80,
"redirects": {
"host": "http://pksunkara.github.com",
"code": 302
}
}
6 changes: 3 additions & 3 deletions lib/redirect.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var http = require('http')

// module.exports is a middleware
module.exports = function (config, port) {
module.exports = function (redirects, port) {
return http.createServer(function (req, res) {
var url = config.host + req.url;
var url = redirects.host + req.url;

res.statusCode = config.code;
res.statusCode = redirects.code;
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Location', url);
res.end('Redirecting to '+url);
Expand Down

0 comments on commit a16c90c

Please sign in to comment.