Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 6dd3a8e01d3c86f3e0a58db66ba6e62c01760347 @donwb donwb committed May 14, 2012
Showing with 178 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +51 −0 app.js
  3. +44 −0 config/config.js
  4. +5 −0 controllers/admin.js
  5. +9 −0 controllers/site.js
  6. +9 −0 models/model.js
  7. +9 −0 package.json
  8. +14 −0 public/stylesheets/style.css
  9. +19 −0 routes.js
  10. +2 −0 views/admin.jade
  11. +1 −0 views/detail.jade
  12. +8 −0 views/index.jade
  13. +6 −0 views/layout.jade
@@ -0,0 +1 @@
+node_modules
51 app.js
@@ -0,0 +1,51 @@
+var express = require('express');
+var config = require('./config/config');
+
+var app = module.exports = express.createServer();
+
+// Check node_env, if not set default to development
+process.env.NODE_ENV = (process.env.NODE_ENV || "development");
+
+// Configuration, defaults to jade as the view engine
+app.configure(function(){
+ app.set('views', __dirname + '/views');
+ app.set('view engine', 'jade');
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(app.router);
+ app.use(express.static(__dirname + '/public'));
+});
+
+/*
+ * This section is for environment specific configuration
+ */
+app.configure('development', function(){
+ config.setDevelopmentConfig();
+ console.log(config.DatabaseConfig);
+ console.log(config.EnvConfig);
+
+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+});
+
+app.configure('production', function(){
+ config.setProductionConfig();
+ console.log(config.DatabaseConfig);
+ console.log(config.EnvConfig);
+
+ app.use(express.errorHandler());
+});
+
+
+app.listen(config.EnvConfig.port, function(){
+ console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
+});
+
+
+/*
+ * Exports the express app for other modules to use
+ * all route matches go the routes.js file
+ */
+module.exports.app = app;
+routes = require('./routes');
+
+
@@ -0,0 +1,44 @@
+/*
+ * modify values in these methods to set
+ * environment specific info
+ */
+function setDevelopmentConfig(){
+ // These are just examples, insert you info here
+ DatabaseConfig.port = 27617;
+ DatabaseConfig.host = '::mongo host::';
+ DatabaseConfig.name = '::collection name::';
+ DatabaseConfig.user = '::db username::';
+ DatabaseConfig.pass = '::db password::';
+
+ EnvConfig.port = 3000;
+};
+
+function setProductionConfig(){
+ DatabaseConfig.port = 29017;
+ DatabaseConfig.host = '::mongo host::';
+ DatabaseConfig.name = '::collection name::';
+ DatabaseConfig.user = '::db username::';
+ DatabaseConfig.pass = '::db password::';
+
+ EnvConfig.port = 80;
+};
+
+/* --- no need to modify below this line -- */
+
+
+var DatabaseConfig = {
+ port : Number,
+ host : String,
+ name : String,
+ user : String,
+ pass : String
+};
+
+var EnvConfig = {
+ port : Number
+};
+
+module.exports.DatabaseConfig = DatabaseConfig;
+module.exports.EnvConfig = EnvConfig;
+module.exports.setDevelopmentConfig = setDevelopmentConfig;
+module.exports.setProductionConfig = setProductionConfig;
@@ -0,0 +1,5 @@
+/* put controller actions here */
+
+exports.admin = function(req, res){
+ res.render('admin', {title: "Admin"});
+}
@@ -0,0 +1,9 @@
+/* put controller actions here */
+
+exports.index = function(req, res){
+ res.render('index', { title: 'Express' })
+};
+
+exports.detail = function(req, res){
+ res.render('detail', {title: 'Detail'});
+}
@@ -0,0 +1,9 @@
+
+/*
+ * This file is intentioually left blank. Depending on how you choose
+ * access the database determines what your models look like.
+ * Currently, we're using the mongo driver directly for some
+ * apps, and using Mongoose for others. Please take a look at
+ * either HiProfile or Flow for some data access patterns
+ */
+
@@ -0,0 +1,9 @@
+{
+ "name": "node-reference"
+ , "version": "0.0.1"
+ , "private": true
+ , "dependencies": {
+ "express": "2.5.8"
+ , "jade": ">= 0.0.1"
+ }
+}
@@ -0,0 +1,14 @@
+body {
+ padding: 50px;
+ font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+ color: #00B7FF;
+ margin-left: 10px;
+}
+
+h4 {
+ font-size: 16px;
+ margin-bottom: 3px;
+}
@@ -0,0 +1,19 @@
+/* This file maps your route matches
+ * to functions defined in various
+ * controller classes
+ */
+app = module.parent.exports.app;
+
+/* require your controllers here */
+var siteController = require('./controllers/site');
+var adminController = require('./controllers/admin');
+
+/* Put routes here */
+
+// main site routes
+app.get('/', siteController.index);
+app.get('/detail', siteController.detail);
+
+// admin routes
+app.get('/admin', adminController.admin);
+
@@ -0,0 +1,2 @@
+h2 Admin
+h4 Hello from the admin view
@@ -0,0 +1 @@
+h3 This is the detail view
@@ -0,0 +1,8 @@
+h1= title
+p Welcome to #{title}
+
+h4 Take me to:
+div
+ a(href="/detail") The detail page
+div
+ a(href="/admin") The admin page
@@ -0,0 +1,6 @@
+!!!
+html
+ head
+ title= title
+ link(rel='stylesheet', href='/stylesheets/style.css')
+ body!= body

0 comments on commit 6dd3a8e

Please sign in to comment.