Permalink
Browse files

Implement info pages as an app, apply to both servers

  • Loading branch information...
1 parent aa3d9b8 commit f938291cf93a0b988197931f800da8af476646e7 @evdb evdb committed Apr 24, 2012
Showing with 35 additions and 23 deletions.
  1. +7 −0 docs/project_layout.md
  2. +1 −0 hosting-app/app.js
  3. +0 −3 hosting-app/routes/index.js
  4. +0 −20 hosting-app/routes/info.js
  5. +1 −0 instance-app/app.js
  6. +26 −0 lib/apps/info.js
@@ -41,3 +41,10 @@ Each app has it's own folder with the usual sub folders:
Note that many of the `require` statements will refer to files one level above
the app folder, so there may be more `../` than normal :)
+
+### Views
+
+In each app folder there is a `views` folder that contains the templates. There
+is also a folders in `views` called `info`. Any template put in there will be
+served when requested at a url like `/info/foobar` - which would serve the
+`info/foobar.jade` template. This is useful for privacy policies etc.
View
@@ -32,6 +32,7 @@ app.configure(function(){
app.use(express.methodOverride());
app.use(express.static(__dirname + '/../public'));
+ app.use('/info', require('../lib/apps/info') );
app.use(app.router);
app.use( require('../lib/errors').errorHandler );
@@ -213,9 +213,6 @@ exports.route = function (app) {
});
-
- require('./info').route(app);
-
// Throw a 404 error
app.all('/*', function(req, res, next) {
next(new Error404());
@@ -1,20 +0,0 @@
-var path = require('path'),
- Error404 = require('../../lib/errors').Error404;
-
-exports.route = function (app) {
- app.get('/info/:page', function(req, res, next){
-
- var template_file = req.app.set('views') + '/info/' + req.param('page') + '.jade';
-
- path.exists(template_file, function (exists) {
- if (exists) {
- res.render( 'info/' + req.param('page') );
- } else {
- next(new Error404());
- }
- });
-
- });
-};
-
-
View
@@ -111,6 +111,7 @@ app.configure(function(){
app.use( everyauth.middleware() );
+ app.use('/info', require('../lib/apps/info') );
app.use(app.router);
app.use( require('../lib/errors').errorHandler );
View
@@ -0,0 +1,26 @@
+var express = require('express'),
+ path = require('path'),
+ Error404 = require('../errors').Error404;
+
+var info_app = express.createServer();
+
+info_app.mounted(function(parent){
+
+ this.get('/:page', function(req, res, next){
+
+ var template_file = req.app.set('views') + '/info/' + req.param('page') + '.jade';
+
+ path.exists(template_file, function (exists) {
+ if (exists) {
+ res.render( 'info/' + req.param('page') );
+ } else {
+ next(new Error404());
+ }
+ });
+
+ });
+
+});
+
+module.exports = info_app;
+

0 comments on commit f938291

Please sign in to comment.