Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more fixes

  • Loading branch information...
commit 38508f025d6a26f40a5f84c0e1e8e372b277a198 1 parent 39d45df
@fjakobs fjakobs authored
Showing with 6 additions and 102 deletions.
  1. +0 −84 example/api/index.js
  2. +0 −12 example/package.json
  3. +6 −6 frontdoor.js
View
84 example/api/index.js
@@ -1,84 +0,0 @@
-var frontdoor = require("../../frontdoor");
-var errors = require("http-error");
-
-module.exports = function() {
- var api = frontdoor("TODO app");
-
- var todo = new Todo();
- todo.add({description: "get a hair cut"}, function() {});
- todo.add({description: "buy milk"}, function() {});
- todo.update({id: 1, done: true}, function() {});
-
- api.section("todo").get("/", todo.list.bind(todo))
- .put("/", {
- params: {
- description: {
- type: "string",
- source: "body"
- }
- }
- }, todo.add.bind(todo))
- .post("/:id", {
- params: {
- id: "int",
- done: {
- type: "boolean",
- source: "body",
- optional: true
- },
- description: {
- type: "string",
- source: "body",
- optional: true
- }
- }
- }, todo.update.bind(todo))
- .delete("/:id", {
- params: { id: "int" }
- }, todo.remove.bind(todo));
-
- api.get("/inspect.json", frontdoor.mw.describeApi(api));
-
- return api;
-};
-
-function Todo() {
- this.items = {};
- this._id = 1;
-}
-Todo.prototype.list = function(params, callback) {
- var res = { items: [] };
- for (var id in this.items)
- res.items.push(this.items[id]);
- callback(null, res);
-};
-Todo.prototype.add = function(params, callback) {
- var id = this._id++;
- this.items[id] = {
- id: id,
- done: false,
- description: params.description
- };
- callback(null, { id: params.id });
-};
-Todo.prototype.update = function(params, callback) {
- var item = this.items[params.id];
- if (!item)
- return callback(new errors.NotFound("No such entry " + params.id));
-
- if ("done" in params)
- item.done = params.done;
-
- if ("description" in params)
- item.description = params.description;
-
- callback(null, { id: params.id });
-};
-Todo.prototype.remove = function(params, callback) {
- var item = this.items[params.id];
- if (!item)
- return callback(new errors.NotFound("No such entry " + params.id));
-
- delete this.items[params.id];
- callback(null, { id: params.id });
-};
View
12 example/package.json
@@ -1,12 +0,0 @@
-{
- "name": "application-name",
- "version": "0.0.1",
- "private": true,
- "scripts": {
- "start": "node app"
- },
- "dependencies": {
- "express": "3.0.3",
- "ejs": "*"
- }
-}
View
12 frontdoor.js
@@ -1,16 +1,16 @@
"use strict";
-var Route = require("./route");
-var Section = require("./section");
-var middleware = require("./middleware");
-var api = require("./lib/api");
+var Route = require("./lib/route");
+var Section = require("./lib/section");
+var middleware = require("./lib/middleware");
+var Api = require("./lib/api");
module.exports = function(description) {
- return new api.Api(description);
+ return new Api(description);
};
module.exports.Section = Section;
module.exports.Route = Route;
-module.exports.midleware = middleware;
+module.exports.middleware = middleware;
Please sign in to comment.
Something went wrong with that request. Please try again.