Permalink
Browse files

remove route-loading example

using vm for this is lame
  • Loading branch information...
1 parent 056c840 commit 3923ec89f7a2d54cd5c1bcd2fcdc824b1aed5755 @tj tj committed Aug 9, 2012
@@ -1,26 +0,0 @@
-
-/**
- * Module dependencies.
- */
-
-var vm = require('vm')
- , fs = require('fs');
-
-module.exports = function(app, db){
- var dir = __dirname + '/routes';
- // grab a list of our route files
- fs.readdirSync(dir).forEach(function(file){
- var str = fs.readFileSync(dir + '/' + file, 'utf8');
- // inject some pseudo globals by evaluating
- // the file with vm.runInNewContext()
- // instead of loading it with require(). require's
- // internals use similar, so dont be afraid of "boot time".
- var context = { app: app, db: db };
- // we have to merge the globals for console, process etc
- for (var key in global) context[key] = global[key];
- // note that this is essentially no different than ... just using
- // global variables, though it's only YOUR code that could influence
- // them, which is a bonus.
- vm.runInNewContext(str, context, file);
- });
-};
@@ -1,20 +0,0 @@
-
-/**
- * Module dependencies.
- */
-
-var express = require('../../lib/express')
- , app = express()
- , db = { users: [] };
-
-app.set('views', __dirname + '/views');
-app.set('view engine', 'jade');
-app.use(express.bodyParser());
-
-// pretend db is a database, could be
-// whatever you like
-require('./boot')(app, db);
-
-app.listen(3000);
-console.log('Express app started on port 3000');
-
@@ -1,4 +0,0 @@
-
-app.get('/', function(req, res){
- res.render('index');
-});
@@ -1,18 +0,0 @@
-
-app.get('/users', function(req, res){
- res.render('user/list', { users: db.users });
-});
-
-app.get('/user/add', function(req, res){
- res.render('user/add');
-});
-
-app.post('/user', function(req, res){
- var user = req.body.user;
- db.users.push(user);
- res.redirect('/users');
-});
-
-app.get('/user/:id', function(req, res){
- res.render('user');
-});
@@ -1,8 +0,0 @@
-
-extends layout
-
-block content
- h2 Route sharing example
- ul
- li: a(href='/user/add') Add user
- li: a(href='/users') User list
@@ -1,11 +0,0 @@
-doctype html
-html
- head
- title Route loading example
- style
- body {
- padding: 50px;
- font: 14px/1.5 solid helvetica, arial, sans-serif;
- }
- body
- block content
@@ -1,9 +0,0 @@
-
-extends ../layout
-
-block content
- h2 Add a user
- form(action='/user', method='post')
- p: input(type='text', name='user[name]', placeholder='Username')
- p: input(type='text', name='user[email]', placeholder='Email')
- p: input(type='submit', value='Add')
@@ -1,10 +0,0 @@
-
-extends ../layout
-
-block content
- h1= user.name
- table
- tbody
- tr
- td Email
- td= user.email
@@ -1,10 +0,0 @@
-
-extends ../layout
-
-block content
- h1 Users
- if users.length
- for user in users
- include index
- else
- p No users, head over to <a href='/user/add'>/user/add</a> to create one.

2 comments on commit 3923ec8

@emilecantin

Why is this lame?

@tj
Member
tj commented on 3923ec8 Aug 22, 2012

it's pretty much identical to just using globals

Please sign in to comment.