diff --git a/Gruntfile.js b/Gruntfile.js index bf847e4..c02355b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -19,7 +19,7 @@ module.exports = function (grunt) { options: { async: true }, - command: 'node server/server.js' + command: 'node app.js' } }, jshint: { diff --git a/app.js b/app.js new file mode 100644 index 0000000..56e2580 --- /dev/null +++ b/app.js @@ -0,0 +1,67 @@ +var habitat = require('habitat'); +var express = require('express'); +var nunjucks = require('nunjucks'); +var path = require('path'); +var i18n = require('webmaker-i18n'); +var nunjucksEnv = new nunjucks.Environment( new nunjucks.FileSystemLoader(path.join(__dirname, 'views'))); + +habitat.load(); + +var app = express(), + env = new habitat(); + +app.use(express.logger('dev')); +app.use(express.compress()); +app.use(express.json()); +app.use(express.urlencoded()); + +nunjucksEnv.express(app); +nunjucksEnv.addFilter('instantiate', function(input) { + var tmpl = new nunjucks.Template(input); + return tmpl.render(this.getVariables()); +}); + +var healthcheck = { + version: require('./package').version, + http: 'okay' +}; + +// Setup locales with i18n +app.use( i18n.middleware({ + supported_languages: [ 'en-US' ], + default_lang: 'en-US', + mappings: require('webmaker-locale-mapping'), + translation_directory: path.resolve(__dirname, 'locale') +})); + +// Static files +app.use(express.static(path.resolve(__dirname, 'public'))); + +// Healthcheck +app.get('/healthcheck', function (req, res) { + res.json(healthcheck); +}); + +app.get('/', function(req, res){ + res.render('home.html'); +}); + +app.get('/partners', function(req, res){ + res.render('partners.html'); +}); + +app.get('/resources', function(req, res){ + res.render('resources.html'); +}); + +app.get('/history', function(req, res){ + res.render('history.html'); +}); + +// Localized Strings +app.get('/strings/:lang?', i18n.stringsRoute('en-US')); + +// Run server +app.listen(env.get('PORT'), function () { + console.log('Now listening on %d', env.get('PORT')); +}); diff --git a/server/config.js b/server/config.js deleted file mode 100644 index f62eb44..0000000 --- a/server/config.js +++ /dev/null @@ -1,74 +0,0 @@ -module.exports = function (env) { - var express = require('express'); - var nunjucks = require( "nunjucks" ); - var path = require('path'); - var i18n = require( "webmaker-i18n" ); - console.log(i18n); - var app = express(); - var nunjucksEnv = new nunjucks.Environment( new nunjucks.FileSystemLoader( "./public")); - var defaultLang = 'en-US'; - var appVersion = require('../package').version; - - app.use(express.logger('dev')); - app.use(express.compress()); - app.use(express.json()); - app.use(express.urlencoded()); - - nunjucksEnv.express( app ); - nunjucksEnv.addFilter( "instantiate", function( input ) { - var tmpl = new nunjucks.Template( input ); - return tmpl.render( this.getVariables() ); - }); - - var config = { - version: appVersion - }; - - var healthcheck = { - version: appVersion, - http: 'okay' - }; - - // Setup locales with i18n - app.use( i18n.middleware({ - supported_languages: [ "*" ], // TO FIX: config.SUPPORTED_LANGS ??? - default_lang: "en-US", - mappings: require("webmaker-locale-mapping"), - translation_directory: path.resolve( __dirname, "../locale" ) - })); - - // Localized Strings - app.get("/strings/:lang?", i18n.stringsRoute("en-US")); - - // Static files - app.use(express.static('./public')); - - // Healthcheck - app.get('/healthcheck', function (req, res) { - res.json(healthcheck); - }); - - // Serve up virtual configuration "file" - app.get('/config.js', function (req, res) { - res.setHeader('Content-type', 'text/javascript'); - res.send('window.eventsConfig = ' + JSON.stringify(config)); - }); - - app.get('/', function(req, res){ - res.render("views/home.html"); - }); - - app.get('/partners', function(req, res){ - res.render("views/partners.html"); - }); - - app.get('/resources', function(req, res){ - res.render("views/resources.html"); - }); - - app.get('/history', function(req, res){ - res.render("views/history.html"); - }); - - return app; -}; diff --git a/server/server.js b/server/server.js deleted file mode 100644 index e563930..0000000 --- a/server/server.js +++ /dev/null @@ -1,14 +0,0 @@ -var Habitat = require('habitat'); - -Habitat.load(); - -// Configuration -var env = new Habitat(); - -// App -var app = require('./config')(env); - -// Run server -app.listen(env.get('PORT'), function () { - console.log('Now listening on %d', env.get('PORT')); -}); diff --git a/views/layout.html b/views/layout.html index 9fd8000..750b8ed 100644 --- a/views/layout.html +++ b/views/layout.html @@ -145,7 +145,6 @@ -