Last active
December 15, 2015 05:59
-
-
Save adamvr/5213387 to your computer and use it in GitHub Desktop.
CMS design notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
- 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)
- mongoose
- node_redis
- for user session management
- 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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