Skip to content

Commit 248e03e

Browse files
committed
Fix CLI
1 parent 57504d9 commit 248e03e

File tree

4 files changed

+119
-4
lines changed

4 files changed

+119
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
**/*.logq
1+
**/*.log
22
node_modules
33
db.json
44
.DS_Store

bin/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var yargs = require('yargs')
55
var chalk = require('chalk')
66
var got = require('got')
77
var pkg = require('../package.json')
8-
var server = require('../src')
8+
var jsonServer = require('../src')
99

1010
updateNotifier({packageName: pkg.name, packageVersion: pkg.version}).notify()
1111

@@ -51,7 +51,15 @@ function start(object, filename) {
5151
}
5252
})
5353

54-
server(object, filename).listen(port)
54+
if (filename) {
55+
var router = jsonServer.router(filename)
56+
} else {
57+
var router = jsonServer.router(object)
58+
}
59+
var server = jsonServer.create()
60+
61+
server.use(router)
62+
server.listen(port)
5563
}
5664

5765
// Set file and port

npm-debug.log

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
0 info it worked if it ends with ok
2+
1 verbose cli [ '/home/sonic/.nvm/v0.10.35/bin/node',
3+
1 verbose cli '/home/sonic/.nvm/v0.10.35/bin/npm',
4+
1 verbose cli 'publish' ]
5+
2 info using [email protected]
6+
3 info using [email protected]
7+
4 verbose publish [ '.' ]
8+
5 verbose cache add [ '.', null ]
9+
6 verbose cache add name=undefined spec="." args=[".",null]
10+
7 verbose parsed url { protocol: null,
11+
7 verbose parsed url slashes: null,
12+
7 verbose parsed url auth: null,
13+
7 verbose parsed url host: null,
14+
7 verbose parsed url port: null,
15+
7 verbose parsed url hostname: null,
16+
7 verbose parsed url hash: null,
17+
7 verbose parsed url search: null,
18+
7 verbose parsed url query: null,
19+
7 verbose parsed url pathname: '.',
20+
7 verbose parsed url path: '.',
21+
7 verbose parsed url href: '.' }
22+
8 silly lockFile 3a52ce78- .
23+
9 verbose lock . /home/sonic/.npm/3a52ce78-.lock
24+
10 verbose tar pack [ '/home/sonic/.npm/json-server/0.6.0/package.tgz', '.' ]
25+
11 verbose tarball /home/sonic/.npm/json-server/0.6.0/package.tgz
26+
12 verbose folder .
27+
13 info prepublish [email protected]
28+
14 silly lockFile 1f1177db-tar tar://.
29+
15 verbose lock tar://. /home/sonic/.npm/1f1177db-tar.lock
30+
16 silly lockFile a26da56b-pm-json-server-0-6-0-package-tgz tar:///home/sonic/.npm/json-server/0.6.0/package.tgz
31+
17 verbose lock tar:///home/sonic/.npm/json-server/0.6.0/package.tgz /home/sonic/.npm/a26da56b-pm-json-server-0-6-0-package-tgz.lock
32+
18 silly lockFile 1f1177db-tar tar://.
33+
19 silly lockFile 1f1177db-tar tar://.
34+
20 silly lockFile a26da56b-pm-json-server-0-6-0-package-tgz tar:///home/sonic/.npm/json-server/0.6.0/package.tgz
35+
21 silly lockFile a26da56b-pm-json-server-0-6-0-package-tgz tar:///home/sonic/.npm/json-server/0.6.0/package.tgz
36+
22 silly lockFile cc6cdab6-ic-npm-json-server-0-6-0-package /home/sonic/.npm/json-server/0.6.0/package
37+
23 verbose lock /home/sonic/.npm/json-server/0.6.0/package /home/sonic/.npm/cc6cdab6-ic-npm-json-server-0-6-0-package.lock
38+
24 silly lockFile cc6cdab6-ic-npm-json-server-0-6-0-package /home/sonic/.npm/json-server/0.6.0/package
39+
25 silly lockFile cc6cdab6-ic-npm-json-server-0-6-0-package /home/sonic/.npm/json-server/0.6.0/package
40+
26 silly lockFile 3a52ce78- .
41+
27 silly lockFile 3a52ce78- .
42+
28 silly publish { name: 'json-server',
43+
28 silly publish version: '0.6.0',
44+
28 silly publish description: 'Serves JSON files through REST routes.',
45+
28 silly publish main: './src/index.js',
46+
28 silly publish bin: { 'json-server': './bin/index.js' },
47+
28 silly publish directories: { test: 'test' },
48+
28 silly publish dependencies:
49+
28 silly publish { 'body-parser': '^1.8.1',
50+
28 silly publish chalk: '^0.4.0',
51+
28 silly publish cors: '^2.3.0',
52+
28 silly publish errorhandler: '^1.2.0',
53+
28 silly publish express: '^4.9.5',
54+
28 silly publish got: '^1.2.2',
55+
28 silly publish lowdb: '^0.7.1',
56+
28 silly publish 'method-override': '^2.1.2',
57+
28 silly publish morgan: '^1.3.1',
58+
28 silly publish 'node-uuid': '^1.4.2',
59+
28 silly publish 'serve-static': '^1.6.1',
60+
28 silly publish superagent: '^0.15.7',
61+
28 silly publish underscore: '^1.5.2',
62+
28 silly publish 'underscore-db': '^0.8.0',
63+
28 silly publish 'underscore.inflections': '~0.2.1',
64+
28 silly publish 'update-notifier': '^0.2.2',
65+
28 silly publish yargs: '^1.3.1' },
66+
28 silly publish devDependencies: { husky: '^0.6.1', mocha: '~1.14.0', supertest: '~0.8.1' },
67+
28 silly publish scripts:
68+
28 silly publish { test: 'mocha -R spec test',
69+
28 silly publish start: 'node server.js',
70+
28 silly publish prepush: 'npm t' },
71+
28 silly publish repository:
72+
28 silly publish { type: 'git',
73+
28 silly publish url: 'git://github.com/typicode/json-server.git' },
74+
28 silly publish keywords:
75+
28 silly publish [ 'JSON',
76+
28 silly publish 'server',
77+
28 silly publish 'fake',
78+
28 silly publish 'REST',
79+
28 silly publish 'API',
80+
28 silly publish 'prototyping',
81+
28 silly publish 'mock',
82+
28 silly publish 'mocking',
83+
28 silly publish 'test',
84+
28 silly publish 'testing',
85+
28 silly publish 'rest',
86+
28 silly publish 'data',
87+
28 silly publish 'dummy',
88+
28 silly publish 'sandbox' ],
89+
28 silly publish author: { name: 'Typicode', email: '[email protected]' },
90+
28 silly publish license: 'MIT',
91+
28 silly publish bugs: { url: 'https://github.com/typicode/json-server/issues' },
92+
28 silly publish homepage: 'https://github.com/typicode/json-server',
93+
28 silly publish readme: '# JSON Server [![Build Status](https://travis-ci.org/typicode/json-server.svg)](https://travis-ci.org/typicode/json-server) [![NPM version](https://badge.fury.io/js/json-server.svg)](http://badge.fury.io/js/json-server)\n\n> Get a full fake REST API with __zero coding__ in __less than 30 seconds__ (seriously)\n\nCreated with <3 for front-end developers who need a quick back-end for prototyping and mocking.\n\nPowers [JSONPlaceholder](http://jsonplaceholder.typicode.com)\n\n## Example\n\nCreate a `db.json` file\n\n```javascript\n{\n "posts": [\n { "id": 1, "title": "json-server", "author": "typicode" }\n ],\n "comments": [\n { "id": 1, "body": "some comment", "postId": 1 }\n ]\n}\n```\n\nStart JSON Server\n\n```bash\n$ json-server db.json\n```\n\nNow if you go to [http://localhost:3000/posts/1](), you\'ll get\n\n```javascript\n{ \n "id": 1,\n "body": "foo"\n}\n```\n\nAlso, if you make POST, PUT, PATCH or DELETE requests, changes will be saved to `db.json`\n\n## Routes\n\nHere are all the available routes.\n\n```\nGET /posts\nGET /posts/1\nGET /posts/1/comments\nGET /posts?title=json-server&author=typicode\nPOST /posts\nPUT /posts/1\nPATCH /posts/1\nDEL /posts/1\n```\n\nTo slice resources, add `_start` and `_end`.\n\n```\nGET /posts?_start=0&_end=10\nGET /posts/1/comments?_start=0&_end=10\n```\n\nTo sort resources, add `_sort` and `_order` (ascending order by default).\n\n```\nGET /posts?_sort=views&_order=DESC\nGET /posts/1/comments?_sort=votes&_order=ASC\n```\n\nTo make a full-text search on resources, add `q`.\n\n```\nGET /posts?q=internet\n```\n\nReturns database.\n\n```\nGET /db\n```\n\nReturns default index file or serves `./public` directory.\n\n```\nGET /\n```\n\n## Install\n\n```bash\n$ npm install -g json-server\n```\n\n## Extras\n\n### Static file server\n\nYou can use JSON Server to serve your HTML, JS and CSS, simply create a `./public` directory.\n\n### Access from anywhere\n\nYou can access your fake API from anywhere using CORS and JSONP.\n\n### Remote schema\n\nYou can load remote schemas:\n\n```bash\n$ json-server http://example.com/file.json\n$ json-server http://jsonplaceholder.typicode.com/db\n```\n\n### JS file support\n\nYou can use JS to programmatically create data:\n\n```javascript\nmodule.exports = function() {\n data = { users: [] }\n // Create 1000 users\n for (var i = 0; i < 1000; i++) {\n data.users.push({ name: \'user\' + i })\n }\n return data\n}\n```\n\n```bash\n$ json-server index.js\n```\n\n### Module\n\nYou can use JSON Server as a module:\n\n```javascript\nvar jsonServer = require(\'json-server\')\n\nvar object = {\n posts: [\n { id: 1, body: \'foo\' }\n ]\n}\n\nvar router = jsonServer.router(object) // Express router\nvar server = jsonServer.create() // Express server\n\nserver.use(router)\nserver.listen(3000)\n```\n\n### Deployment\n\nYou can deploy JSON Server. For example, [JSONPlaceholder](http://jsonplaceholder.typicode.com) is an online fake API powered by JSON Server and running on Heroku.\n\n## Links\n\n### Articles\n\n* [Fast prototyping using Restangular and Json-server](http://bahmutov.calepin.co/fast-prototyping-using-restangular-and-json-server.html)\n* [ng-admin: Add an AngularJS admin GUI to any RESTful API](http://marmelab.com/blog/2014/09/15/easy-backend-for-your-restful-api.html)\n\n### Projects\n\n* [Grunt JSON Server](https://github.com/tfiwm/grunt-json-server)\n* [Docker JSON Server](https://github.com/clue/docker-json-server)\n* [JSON Server GUI](https://github.com/naholyr/json-server-gui)\n\n## License\n\nMIT - [Typicode](https://github.com/typicode)\n',
94+
28 silly publish readmeFilename: 'README.md',
95+
28 silly publish gitHead: '57504d99a8ec63dad58f6bca3534ce53299b46c5',
96+
28 silly publish _id: '[email protected]',
97+
28 silly publish _shasum: 'e56250ef6c29b2eb314ff3094e4180286ca5e9eb',
98+
28 silly publish _from: '.' }
99+
29 error need auth auth and email required for publishing
100+
29 error need auth You need to authorize this machine using `npm adduser`
101+
30 error System Linux 3.17.8-300.fc21.x86_64
102+
31 error command "/home/sonic/.nvm/v0.10.35/bin/node" "/home/sonic/.nvm/v0.10.35/bin/npm" "publish"
103+
32 error cwd /home/sonic/d/json-server
104+
33 error node -v v0.10.35
105+
34 error npm -v 1.4.28
106+
35 error code ENEEDAUTH
107+
36 verbose exit [ 1, true ]

src/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function(source) {
1616
var db = low()
1717
db.object = source
1818
} else {
19-
var db = low(filename)
19+
var db = low(source)
2020
}
2121

2222
// Expose database

0 commit comments

Comments
 (0)