mirror of
https://github.com/jimeh/heartb.it.git
synced 2026-02-19 04:46:40 +00:00
switch to using and running *.coffee files instead of *.js as this is an app, not a package
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
docs
|
||||
*.js
|
||||
10
Makefile
10
Makefile
@@ -2,22 +2,14 @@
|
||||
.PHONY: build watch docs test deploy
|
||||
|
||||
BIN = ./node_modules/.bin
|
||||
COFFEE_SRC = ./src
|
||||
COFFEE_OUT = ./
|
||||
REPORTER = spec
|
||||
TEST_DIR = ./test
|
||||
|
||||
deploy:
|
||||
git push heroku master
|
||||
|
||||
build:
|
||||
$(BIN)/coffee -c -o $(COFFEE_OUT) $(COFFEE_SRC)
|
||||
|
||||
watch:
|
||||
$(BIN)/coffee -cw -o $(COFFEE_OUT) $(COFFEE_SRC)
|
||||
|
||||
docs:
|
||||
$(BIN)/docco $(shell find $(COFFEE_SRC) -name '*.coffee')
|
||||
|
||||
test:
|
||||
$(BIN)/mocha -R $(REPORTER) $(TEST_DIR)/*.js
|
||||
$(BIN)/mocha -R $(REPORTER) $(shell find $(TEST_DIR) -name '*.test.coffee')
|
||||
|
||||
47
heartbit.js
47
heartbit.js
@@ -1,47 +0,0 @@
|
||||
(function() {
|
||||
var express, server;
|
||||
|
||||
express = require('express');
|
||||
|
||||
server = module.exports = express.createServer();
|
||||
|
||||
server.configure(function() {
|
||||
server.set('views', __dirname + '/views');
|
||||
server.set('view engine', 'coffee');
|
||||
server.register('.coffee', require('coffeekup').adapters.express);
|
||||
server.use(express.bodyParser());
|
||||
server.use(express.methodOverride());
|
||||
return server.use(express.static(__dirname + '/public'));
|
||||
});
|
||||
|
||||
server.configure('development', function() {
|
||||
return server.use(express.errorHandler({
|
||||
dumpExceptions: true,
|
||||
showStack: true
|
||||
}));
|
||||
});
|
||||
|
||||
server.configure('production', function() {
|
||||
server.use(express.errorHandler());
|
||||
return server.use(require('./middleware/host_redirect')({
|
||||
"www.heartb.it": "http://heartb.it/"
|
||||
}));
|
||||
});
|
||||
|
||||
server.get('/', function(req, res) {
|
||||
return res.render('index', {
|
||||
format: true
|
||||
});
|
||||
});
|
||||
|
||||
server.get('*', function(req, res) {
|
||||
return res.render('404', {
|
||||
format: true
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(process.env.PORT || 3000);
|
||||
|
||||
console.log("Express server listening on port %d in %s mode", server.address().port, server.settings.env);
|
||||
|
||||
}).call(this);
|
||||
@@ -1,16 +0,0 @@
|
||||
(function() {
|
||||
|
||||
module.exports = function(redirect_map) {
|
||||
if (redirect_map == null) redirect_map = {};
|
||||
return function(req, res, next) {
|
||||
var host;
|
||||
host = req.header('Host');
|
||||
if (redirect_map[host]) {
|
||||
return res.redirect(redirect_map[host]);
|
||||
} else {
|
||||
return next();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
@@ -11,5 +11,9 @@
|
||||
"docco": "*",
|
||||
"mocha": "*",
|
||||
"should": "*"
|
||||
},
|
||||
"engine": {
|
||||
"node": "0.6.x",
|
||||
"npm": "1.x.x"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
(function() {
|
||||
var host_redirect;
|
||||
|
||||
require('should');
|
||||
|
||||
host_redirect = require('../middleware/host_redirect');
|
||||
|
||||
describe('host_redirect', function() {
|
||||
var redirect_map, redirector;
|
||||
redirect_map = {
|
||||
'www.foo.com': 'http://foo.com/',
|
||||
'img.foo.com': 'http://images.foo.com/'
|
||||
};
|
||||
redirector = host_redirect(redirect_map);
|
||||
describe('when request does not match any entry in map', function() {
|
||||
return it('next() is called to pass on the request', function(done) {
|
||||
var next, req, res;
|
||||
req = {
|
||||
header: function() {
|
||||
return 'www.bar.com';
|
||||
}
|
||||
};
|
||||
res = {};
|
||||
next = function() {
|
||||
return done();
|
||||
};
|
||||
return redirector(req, res, next);
|
||||
});
|
||||
});
|
||||
return describe('when request matches an entry in map', function() {
|
||||
return it('req.redirect() is called with the new URL', function(done) {
|
||||
var next, req, res;
|
||||
req = {
|
||||
header: function() {
|
||||
return 'img.foo.com';
|
||||
}
|
||||
};
|
||||
res = {
|
||||
redirect: function(url) {
|
||||
url.should.equal(redirect_map[req.header()]);
|
||||
return done();
|
||||
}
|
||||
};
|
||||
next = function() {};
|
||||
return redirector(req, res, next);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'should'
|
||||
|
||||
host_redirect = require '../middleware/host_redirect'
|
||||
host_redirect = require '../../middleware/host_redirect'
|
||||
|
||||
describe 'host_redirect', ->
|
||||
|
||||
Reference in New Issue
Block a user