Created
September 24, 2014 13:55
-
-
Save stuf/31a554b5be1fac2b7f81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var express = require('express'); | |
var logger = require('morgan'); | |
var bodyParser = require('body-parser'); | |
var fs = require('fs'); | |
var util = require('util'); | |
var http = require('http'); | |
var Q = require('q'); | |
var _ = require('underscore'); | |
var router = express.Router(); | |
var app = express(); | |
var VERSION = '0.0.2'; | |
// Eyecandy | |
require('colors'); | |
util.log('Info Radiator RESTful API ' + VERSION.bold + ''); | |
// ============================================================================= | |
app.use(bodyParser.urlencoded({ extended: false })); | |
app.use(bodyParser.json()); | |
var port = process.env.PORT || 8080; | |
// Routing | |
// ============================================================================= | |
util.log('Initialising modules:'); | |
var base = '/api'; | |
fs.readdirSync('./routes').forEach(function (it, i, list) { | |
util.log(util.format('Including module %s (%d/%d)', it.bold, (i + 1), list.length)); | |
var mod = require('./routes/' + it); | |
app.use(base, mod.router); | |
}); | |
util.log('...Done.'); | |
util.log('Attaching routing to base URL ' + base.bold); | |
app.use(base, router); | |
// Finally | |
// ===================================z========================================== | |
util.log('Preparing to serve...'); | |
app.listen(port); | |
util.log('...Done.'); | |
util.log('Serving at port ' + ('' + port).bold); | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment