Skip to content

Instantly share code, notes, and snippets.

@adamvr
Last active December 15, 2015 05:59
Show Gist options
  • Save adamvr/5213387 to your computer and use it in GitHub Desktop.
Save adamvr/5213387 to your computer and use it in GitHub Desktop.
CMS design notes
var mongoose = require('mongoose');
// TODO: Take schema out so we can add methods to it
Document = module.exports.Document =
mongoose.model('Document', mongoose.Schema({
title: String,
text: String,
tags: [String],
type: { type: String, default: 'markdown' },
createdAt: { type: Date, default: Date.now }
});
var mongoose = require('mongoose');
Image = module.exports.Image =
mongoose.model('Image', mongoose.Schema({
title: String,
image: Buffer,
tags: [String],
type: { type: String, default: 'jpg' },
createdAt: { type: Date, default: Date.now }
});
/**
* Module deps
*/
var express = require('express')
, resource = require('express-resource')
, routes = require('./routes')
, mongoose = require('mongoose');
var app = module.exports = express();
/**
* Mongo connection
*/
mongoose.connect('mongodb://localhost/test');
app.mongoose = mongoose;
app.configure(function () {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.get('/', routes.index);
app.resource('documents', require('./routes/documents'));
app.resource('images', require('./routes/images'));
app.listen(3000);

Routing

  • express
  • express-resource
    • resourceful routing (index, new, create, show, edit, update, destroy)
    • content negotiation (ask for /post/5.json and get the raw mongo doc)

View handling

Databases

Authentication

Testing

Miscellaneous

  • component for managing frontend bits. Possibly out of project scope.
  • kue for job queuing, perhaps necessary if we do some transformations on incoming/outgoing content (e.g. resizing images, video encoding)

Structure

  • app.js (main app)
  • package.json
  • views/
    • index.jade (main page)
    • layout.jade (global page layout, headers, footers, sidebars etc.)
    • document/ (views for documents)
      • index.jade (GET /documents)
      • new.jade (GET /documents/new, GET /documents/edit)
      • show.jade (GET /documents/:id)
    • user/ (views for users)
  • routes/
    • index.js (static routes, eg. home, projects, jobs, blog)
    • user.js (user resource)
    • search.js (search route(s))
    • document.js (document resource)
  • public/ (js, css)
  • models/
    • document.js (schema and models)
// Static routes
GET / -> routes.index
GET /blog -> routes.blog
GET /projects -> routes.projects
// Documents
GET /documents -> documents.index
POST /documents -> documents.create
GET /documents/:id -> documents.show
GET /documents/new -> documents.new
GET /documents/edit -> documents.edit
PUT /documents/:id -> documents.update
// Images
GET /images -> images.index
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment