Commit 7565f0a3a2bb8400488b3acd6395b0306df1c5df
iterate towards a working api
Michael Williams committed on 1/7/2016, 10:39:48 AMParent: c8f38fdc12fc63564d14f8dc103917bdbbfcadcd
Files changed
.gitignore | changed |
app/api.js | changed |
app/todos/models.js | added |
app/todos/service.js | added |
app/db.js | added |
app/services/index.js | deleted |
app/stack/index.js | deleted |
app/stack/services.js | deleted |
config/development.js | changed |
package.json | changed |
app/api.js | ||
---|---|---|
@@ -1,12 +1,28 @@ | ||
1 | +const bulk = require('bulk-require') | |
1 | 2 | import feathers from 'feathers' |
2 | -import { mapObjIndexed, reduce, toPairs } from 'ramda' | |
3 | +import hooks from 'feathers-hooks' | |
4 | +import rest from 'feathers-rest' | |
5 | +import bodyParser from 'body-parser' | |
6 | +import { map, mapObjIndexed, reduce, toPairs } from 'ramda' | |
3 | 7 | |
4 | -import services from 'app/services' | |
5 | -import config from 'app/config' | |
8 | +const services = { | |
9 | + ...map( | |
10 | + (module) => module.service.default, | |
11 | + bulk(__dirname, '*/service.js') | |
12 | + ), | |
13 | + ...map( | |
14 | + (module) => module.services.map(m => m.default), | |
15 | + bulk(__dirname, '*/services/*.js') | |
16 | + ) | |
17 | +} | |
6 | 18 | |
7 | 19 | export default function createServer (config) { |
8 | 20 | const app = feathers() |
21 | + .configure(rest()) | |
22 | + .configure(hooks()) | |
23 | + .use(bodyParser.json()) | |
24 | + .use(bodyParser.urlencoded({ extended: true })) | |
9 | 25 | |
10 | 26 | useAll(app, services) |
11 | 27 | |
12 | 28 | return app |
app/todos/models.js | ||
---|---|---|
@@ -1,0 +1,9 @@ | ||
1 | +import t from 'tcomb' | |
2 | + | |
3 | +export const Todo = t.struct({ | |
4 | + id: t.Number, | |
5 | + text: t.String, | |
6 | + complete: t.Boolean | |
7 | +}, 'Todo') | |
8 | + | |
9 | +export const Todos = t.list(Todo, 'Todos') |
app/todos/service.js | ||
---|---|---|
@@ -1,0 +1,16 @@ | ||
1 | +import knexService from 'feathers-knex' | |
2 | +import validate from 'feathers-tcomb' | |
3 | + | |
4 | +import db from 'app/db' | |
5 | + | |
6 | +import { Todo } from './models' | |
7 | + | |
8 | +export default knexService({ | |
9 | + Model: db, | |
10 | + name: 'todos' | |
11 | +}).extend({ | |
12 | + setup: function (app) { | |
13 | + this._super && this._super(app) | |
14 | + validate(app.service('todos'), Todo) | |
15 | + } | |
16 | +}) |
app/db.js | ||
---|---|---|
@@ -1,0 +1,5 @@ | ||
1 | +import knex from 'knex' | |
2 | + | |
3 | +import config from 'app/config' | |
4 | + | |
5 | +export default knex(config.db) |
app/services/index.js | ||
---|---|---|
@@ -1,13 +1,0 @@ | ||
1 | -const bulk = require('bulk-require') | |
2 | -import { map } from 'ramda' | |
3 | - | |
4 | -export default { | |
5 | - ...map( | |
6 | - (module) => m.service.default, | |
7 | - bulk(__dirname, '*/service.js') | |
8 | - ), | |
9 | - ...map( | |
10 | - (module) => module.services.map(m => m.default), | |
11 | - bulk(__dirname, '*/services/*.js') | |
12 | - ) | |
13 | -} |
app/stack/index.js | ||
---|---|---|
@@ -1,34 +1,0 @@ | ||
1 | -import feathers from 'feathers' | |
2 | -import { mapObjIndexed, reduce, toPairs } from 'ramda' | |
3 | - | |
4 | -const stackCreators = { | |
5 | - services: require('./services'), | |
6 | - static: require('./static'), | |
7 | - render: require('./render') | |
8 | -} | |
9 | - | |
10 | -export default function createStack(config) { | |
11 | - const stacks = createStacks(config) | |
12 | - | |
13 | - const app = feathers() | |
14 | - | |
15 | - useAll(app, stacks) | |
16 | - | |
17 | - return app | |
18 | -} | |
19 | - | |
20 | -function createStacks (config) { | |
21 | - return mapObjIndexed( | |
22 | - (stackCreator, name) => { | |
23 | - return stackCreator(config[name]) | |
24 | - }, | |
25 | - stackCreators | |
26 | - ) | |
27 | -} | |
28 | - | |
29 | -function useAll (app, services) { | |
30 | - return reduce((app, [name, service]) => { | |
31 | - return app.use(service) | |
32 | - }, app, toPairs(services)) | |
33 | -} | |
34 | - |
app/stack/services.js |
---|
config/development.js | ||
---|---|---|
@@ -1,2 +1,10 @@ | ||
1 | +const join = require('path').join | |
2 | + | |
1 | 3 | module.exports = { |
4 | + db: { | |
5 | + client: 'sqlite3', | |
6 | + connection: { | |
7 | + filename: join(__dirname, '..', 'db.sqlite') | |
8 | + } | |
9 | + } | |
2 | 10 | } |
package.json | ||
---|---|---|
@@ -90,8 +90,11 @@ | ||
90 | 90 | "ecstatic": "^1.4.0", |
91 | 91 | "envify": "^3.4.0", |
92 | 92 | "evalify": "^1.0.1", |
93 | 93 | "feathers": "^1.2.0", |
94 | + "feathers-hooks": "^0.5.1", | |
95 | + "feathers-rest": "^1.0.0", | |
96 | + "feathers-tcomb": "^1.0.0", | |
94 | 97 | "history": "^1.13.1", |
95 | 98 | "lnfs-cli": "^1.0.1", |
96 | 99 | "npm-run-all": "^1.3.2", |
97 | 100 | "pinkie-promise": "^2.0.0", |
@@ -105,7 +108,8 @@ | ||
105 | 108 | "redux-simple-router": "0.0.10", |
106 | 109 | "redux-thunk": "^1.0.0", |
107 | 110 | "send-data": "^8.0.0", |
108 | 111 | "simple-rc": "^1.0.0", |
112 | + "tcomb": "^2.5.2", | |
109 | 113 | "uglifyify": "^3.0.1" |
110 | 114 | } |
111 | 115 | } |
Built with git-ssb-web