Skip to content

Commit 10ec083

Browse files
committed
folder structure a la rails \o/
1 parent 6417bb0 commit 10ec083

12 files changed

+2735
-18
lines changed

app.js

+20-16
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
/**
33
* Module dependencies.
44
*/
5+
_ = require("./vendor/underscore");
56

6-
var express = require('express');
7+
var Server = {},
8+
express = require('express'),
9+
path = require("path"),
10+
sys = require("sys"),
11+
application_root = __dirname;
12+
13+
global.Server = Server;
14+
Server.root = application_root;
15+
global.app = express.createServer();
716

8-
var app = module.exports = express.createServer();
917

1018
// Configuration
1119

@@ -15,22 +23,19 @@ require('./vendor/nko')('lyXvQ3xB5YL3dZv0', function(err, res) {
1523
console.error(err.stack);
1624
}
1725
});
18-
app.configure(function(){
19-
app.set('views', __dirname + '/views');
20-
app.set('view engine', 'jade');
21-
app.use(express.bodyParser());
22-
app.use(express.methodOverride());
23-
app.use(app.router);
24-
app.use(express.static(__dirname + '/public'));
25-
});
2626

27-
app.configure('development', function(){
28-
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
27+
Server.setup = require("./lib/setup.js").setup({
28+
app: app,
29+
mongoose: require("mongoose"),
30+
express: express,
31+
paths: {
32+
views: path.join(application_root, "app", "views"),
33+
root: path.join(application_root, "public"),
34+
controllers: path.join(application_root, "app", "controllers"),
35+
models: path.join(application_root, "app", "models")
36+
}
2937
});
3038

31-
app.configure('production', function(){
32-
app.use(express.errorHandler());
33-
});
3439

3540
// Routes
3641

@@ -40,5 +45,4 @@ app.get('/', function(req, res){
4045
});
4146
});
4247

43-
app.listen(8080);
4448
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);

app/controllers/index_controller.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var mongoose = require("mongoose");
2+
var actions = {};
3+
user = mongoose.model('User');
4+
actions.index = function(request,response){
5+
user.find({}, function(err, docs){
6+
//sys.puts(sys.inspect(users));
7+
response.render('index',{
8+
results : docs,
9+
total : docs.length
10+
})
11+
});
12+
};
13+
14+
module.exports = actions;

app/models/user.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var mongoose = require("mongoose");
2+
var sys = require("sys");
3+
var schema = new mongoose.Schema({
4+
name : { type: String, default: 'hahaha' }
5+
, age : { type: Number, min: 18, index: true }
6+
, bio : { type: String, match: /[a-z]/ }
7+
, date : { type: Date, default: Date.now }
8+
});
9+
10+
mongoose.model('User', schema);
11+

0 commit comments

Comments
 (0)