Created
November 13, 2011 11:49
-
-
Save Raynos/1362025 to your computer and use it in GitHub Desktop.
Arch demo
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
// bootstrap starts the server, does shit | |
module.exports = function (app) { | |
var routes = readdirSync("/routes"); | |
routes.forEach(function (name) { | |
require("/routes/" + name)(app); | |
}); | |
// MOAR bootstrap | |
// init database connections | |
// configure server | |
app.listen(process.env.PORT); | |
} |
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
// data object talks to database | |
var db = require("db"); | |
module.exports = { | |
store: function () { | |
// store in db | |
} | |
}; |
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
// domain object does domain logic >_< | |
var data = require("../data/x.js"); | |
function sanitize(..) { | |
} | |
var X = function (data) { | |
}; | |
X.prototype.foo = ... | |
module.exports = { | |
create: function (data, cb) { | |
var data = sanitize(data); | |
data.store(data, function (err, result) { | |
cb(X(result)); | |
}); | |
} | |
} |
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
// index is tiny | |
var bootstrap = require("bootstrap"), | |
app = require("socket.io"); | |
bootstrap(app); | |
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
// Router takes incoming requests and puts them through wrappers | |
// It either sends info to data/domain or asks for information from data/domain | |
// it then puts them through the view layer before sending back to client | |
var x = require("../domain/x.js"), | |
view = require("../view/x.js"); | |
module.exports = function (app) { | |
app.on("a", function (data) { | |
if (data.method === "POST") { | |
x.create(data.data, function (obj) { | |
app.emit("a", { | |
type: "create", | |
obj: view.create(obj) | |
}); | |
}); | |
} | |
// yada yada | |
}); | |
}; |
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
// views transform data objects or domain objects into data that you want to send to clients. | |
// Use this to remove properties clients don't care about and minimize bandwidth | |
// Also use this to transform data objects into objects clients want to consume | |
module.exports = { | |
create: function (x) { | |
var o = {}; | |
o["care about"] = x["care about"]; | |
... | |
return o; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment