diff --git a/examples/with-featherjs/.editorconfig b/examples/with-featherjs/.editorconfig new file mode 100644 index 0000000000..e717f5eb63 --- /dev/null +++ b/examples/with-featherjs/.editorconfig @@ -0,0 +1,13 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/examples/with-featherjs/.gitignore b/examples/with-featherjs/.gitignore new file mode 100644 index 0000000000..815b7b2a27 --- /dev/null +++ b/examples/with-featherjs/.gitignore @@ -0,0 +1,35 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Commenting this out is preferred by some people, see +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- +node_modules + +# Users Environment Variables +.lock-wscript + +lib/ +data/ + +# Nuxt +.nuxt/ +dist/ diff --git a/examples/with-featherjs/.jshintrc b/examples/with-featherjs/.jshintrc new file mode 100644 index 0000000000..1c271e2c7f --- /dev/null +++ b/examples/with-featherjs/.jshintrc @@ -0,0 +1,29 @@ +{ + "node": true, + "esnext": true, + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 2, + "latedef": "nofunc", + "newcap": false, + "noarg": true, + "quotmark": "single", + "regexp": true, + "undef": true, + "unused": false, + "strict": false, + "trailing": true, + "smarttabs": true, + "white": false, + "globals": { + "it": true, + "describe": true, + "before": true, + "beforeEach": true, + "after": true, + "afterEach": true + } +} diff --git a/examples/with-featherjs/.npmignore b/examples/with-featherjs/.npmignore new file mode 100644 index 0000000000..40e14ef091 --- /dev/null +++ b/examples/with-featherjs/.npmignore @@ -0,0 +1,30 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Commenting this out is preferred by some people, see +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- +node_modules + +# Users Environment Variables +.lock-wscript + +data/ diff --git a/examples/with-featherjs/LICENSE b/examples/with-featherjs/LICENSE new file mode 100644 index 0000000000..40b7881afa --- /dev/null +++ b/examples/with-featherjs/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Feathers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/examples/with-featherjs/NEDB_BASE_PATH/users.db b/examples/with-featherjs/NEDB_BASE_PATH/users.db new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/with-featherjs/README.md b/examples/with-featherjs/README.md new file mode 100644 index 0000000000..709584aca5 --- /dev/null +++ b/examples/with-featherjs/README.md @@ -0,0 +1,52 @@ +# with-featherjs + +> Nuxt.js with FeatherJS + +## About + +This project uses [Feathers](http://feathersjs.com). An open source web framework for building modern real-time applications. + +## Getting Started + +Getting up and running is as easy as 1, 2, 3. + +1. Make sure you have [NodeJS](https://nodejs.org/) and [npm](https://www.npmjs.com/) installed. +2. Install your dependencies + + ```bash + npm install + ``` + +3. Start your app + + ```bash + npm run dev + ``` + +## Production + +```bash +npm run build +npm start +``` + +## Testing + +Simply run `npm test` and all your tests in the `test/` directory will be run. + +## Scaffolding + +Feathers has a powerful command line interface. Here are a few things it can do: + +```bash +$ npm install -g feathers-cli # Install Feathers CLI + +$ feathers generate service # Generate a new Service +$ feathers generate hook # Generate a new Hook +$ feathers generate model # Generate a new Model +$ feathers help # Show all commands +``` + +## Help + +For more information on all the things you can do with Feathers visit [docs.feathersjs.com](http://docs.feathersjs.com). diff --git a/examples/with-featherjs/config/default.json b/examples/with-featherjs/config/default.json new file mode 100644 index 0000000000..dd3a541a21 --- /dev/null +++ b/examples/with-featherjs/config/default.json @@ -0,0 +1,11 @@ +{ + "host": "localhost", + "port": 3030, + "nedb": "../data/", + "auth": { + "token": { + "secret": "B/UmaCQUlnIn8lNq7h7KjkM5aqlRz+RkiZ/v3cPL72LYavj6d68HtxXfnrb5T70mdZxHjPNsNfBR7YE1sE6Hdg==" + }, + "local": {} + } +} diff --git a/examples/with-featherjs/config/production.json b/examples/with-featherjs/config/production.json new file mode 100644 index 0000000000..6690c58474 --- /dev/null +++ b/examples/with-featherjs/config/production.json @@ -0,0 +1,11 @@ +{ + "host": "with-featherjs-app.feathersjs.com", + "port": 80, + "nedb": "NEDB_BASE_PATH", + "auth": { + "token": { + "secret": "FEATHERS_AUTH_SECRET" + }, + "local": {} + } +} diff --git a/examples/with-featherjs/package.json b/examples/with-featherjs/package.json new file mode 100644 index 0000000000..dbf0274ba0 --- /dev/null +++ b/examples/with-featherjs/package.json @@ -0,0 +1,48 @@ +{ + "name": "with-featherjs", + "description": "Nuxt.js with FeatherJS", + "version": "0.0.0", + "homepage": "", + "main": "src/", + "keywords": [ + "feathers" + ], + "license": "MIT", + "repository": {}, + "author": {}, + "contributors": [], + "bugs": {}, + "engines": { + "node": ">= 0.12.0" + }, + "scripts": { + "test": "npm run jshint && npm run mocha", + "jshint": "jshint src/. test/. --config", + "dev": "DEBUG=nuxt:* node src/", + "build": "nuxt build", + "start": "NODE_ENV=production node src/", + "mocha": "mocha test/ --recursive --timeout=30000" + }, + "dependencies": { + "body-parser": "^1.15.2", + "compression": "^1.6.2", + "cors": "^2.8.1", + "feathers": "^2.0.3", + "feathers-authentication": "^0.7.12", + "feathers-configuration": "^0.3.3", + "feathers-errors": "^2.5.0", + "feathers-hooks": "^1.7.1", + "feathers-nedb": "^2.6.0", + "feathers-rest": "^1.6.0", + "feathers-socketio": "^1.4.2", + "nedb": "^1.8.0", + "nuxt": "^0.9.5", + "passport": "^0.3.2", + "winston": "^2.3.0" + }, + "devDependencies": { + "jshint": "^2.9.4", + "mocha": "^3.2.0", + "request": "^2.79.0" + } +} diff --git a/examples/with-featherjs/pages/about.vue b/examples/with-featherjs/pages/about.vue new file mode 100644 index 0000000000..068bba1b42 --- /dev/null +++ b/examples/with-featherjs/pages/about.vue @@ -0,0 +1,16 @@ + + + diff --git a/examples/with-featherjs/pages/index.vue b/examples/with-featherjs/pages/index.vue new file mode 100644 index 0000000000..9655d7d866 --- /dev/null +++ b/examples/with-featherjs/pages/index.vue @@ -0,0 +1,6 @@ + diff --git a/examples/with-featherjs/src/app.js b/examples/with-featherjs/src/app.js new file mode 100644 index 0000000000..35dc0dc4f0 --- /dev/null +++ b/examples/with-featherjs/src/app.js @@ -0,0 +1,30 @@ +'use strict'; + +const path = require('path'); +const compress = require('compression'); +const cors = require('cors'); +const feathers = require('feathers'); +const configuration = require('feathers-configuration'); +const hooks = require('feathers-hooks'); +const rest = require('feathers-rest'); +const bodyParser = require('body-parser'); +const socketio = require('feathers-socketio'); +const middleware = require('./middleware'); +const services = require('./services'); + +const app = feathers(); + +app.configure(configuration(path.join(__dirname, '..'))); + +app.use(compress()) +.options('*', cors()) +.use(cors()) +.use(bodyParser.json()) +.use(bodyParser.urlencoded({ extended: true })) +.configure(hooks()) +.configure(rest()) +.configure(socketio()) +.configure(services) +.configure(middleware); + +module.exports = app; diff --git a/examples/with-featherjs/src/hooks/index.js b/examples/with-featherjs/src/hooks/index.js new file mode 100644 index 0000000000..1662947e75 --- /dev/null +++ b/examples/with-featherjs/src/hooks/index.js @@ -0,0 +1,13 @@ +'use strict'; + +// Add any common hooks you want to share across services in here. +// +// Below is an example of how a hook is written and exported. Please +// see http://docs.feathersjs.com/hooks/readme.html for more details +// on hooks. + +exports.myHook = function(options) { + return function(hook) { + console.log('My custom global hook ran. Feathers is awesome!'); + }; +}; diff --git a/examples/with-featherjs/src/index.js b/examples/with-featherjs/src/index.js new file mode 100644 index 0000000000..5adedb5981 --- /dev/null +++ b/examples/with-featherjs/src/index.js @@ -0,0 +1,15 @@ +'use strict'; + +const app = require('./app'); +const port = app.get('port'); + +process.on('nuxt:build:done', (err) => { + if (err) { + console.error(err); + process.exit(1); + } + const server = app.listen(port); + server.on('listening', () => + console.log(`Feathers application started on ${app.get('host')}:${port}`) + ); +}); diff --git a/examples/with-featherjs/src/middleware/index.js b/examples/with-featherjs/src/middleware/index.js new file mode 100644 index 0000000000..5b02e5c679 --- /dev/null +++ b/examples/with-featherjs/src/middleware/index.js @@ -0,0 +1,12 @@ +'use strict'; + +const nuxt = require('./nuxt'); + +module.exports = function() { + // Add your custom middleware here. Remember, that + // just like Express the order matters, so error + // handling middleware should go last. + const app = this; + + app.use(nuxt); +}; diff --git a/examples/with-featherjs/src/middleware/nuxt.js b/examples/with-featherjs/src/middleware/nuxt.js new file mode 100644 index 0000000000..d473826111 --- /dev/null +++ b/examples/with-featherjs/src/middleware/nuxt.js @@ -0,0 +1,22 @@ +const resolve = require('path').resolve; +const Nuxt = require('nuxt'); + +// Setup nuxt.js +let config = {}; +try { + config = require('../../nuxt.config.js'); +} catch (e) {} +config.rootDir = resolve(__dirname, '..', '..'); +config.dev = process.env.NODE_ENV !== 'production'; +const nuxt = new Nuxt(config); +if (config.dev) { + nuxt.build().then(() => { + process.emit('nuxt:build:done'); + }); +} else { + process.nextTick(() => process.emit('nuxt:build:done')); +} +// Add nuxt.js middleware +module.exports = function (req, res) { + nuxt.render(req, res); +}; diff --git a/examples/with-featherjs/src/services/authentication/index.js b/examples/with-featherjs/src/services/authentication/index.js new file mode 100644 index 0000000000..d5a66b56a7 --- /dev/null +++ b/examples/with-featherjs/src/services/authentication/index.js @@ -0,0 +1,14 @@ +'use strict'; + +const authentication = require('feathers-authentication'); + + +module.exports = function() { + const app = this; + + let config = app.get('auth'); + + + + app.configure(authentication(config)); +}; diff --git a/examples/with-featherjs/src/services/index.js b/examples/with-featherjs/src/services/index.js new file mode 100644 index 0000000000..dd7c9d040f --- /dev/null +++ b/examples/with-featherjs/src/services/index.js @@ -0,0 +1,11 @@ +'use strict'; +const authentication = require('./authentication'); +const user = require('./user'); + +module.exports = function() { + const app = this; + + + app.configure(authentication); + app.configure(user); +}; diff --git a/examples/with-featherjs/src/services/user/hooks/index.js b/examples/with-featherjs/src/services/user/hooks/index.js new file mode 100644 index 0000000000..1cbed8a51a --- /dev/null +++ b/examples/with-featherjs/src/services/user/hooks/index.js @@ -0,0 +1,51 @@ +'use strict'; + +const globalHooks = require('../../../hooks'); +const hooks = require('feathers-hooks'); +const auth = require('feathers-authentication').hooks; + +exports.before = { + all: [], + find: [ + auth.verifyToken(), + auth.populateUser(), + auth.restrictToAuthenticated() + ], + get: [ + auth.verifyToken(), + auth.populateUser(), + auth.restrictToAuthenticated(), + auth.restrictToOwner({ ownerField: '_id' }) + ], + create: [ + auth.hashPassword() + ], + update: [ + auth.verifyToken(), + auth.populateUser(), + auth.restrictToAuthenticated(), + auth.restrictToOwner({ ownerField: '_id' }) + ], + patch: [ + auth.verifyToken(), + auth.populateUser(), + auth.restrictToAuthenticated(), + auth.restrictToOwner({ ownerField: '_id' }) + ], + remove: [ + auth.verifyToken(), + auth.populateUser(), + auth.restrictToAuthenticated(), + auth.restrictToOwner({ ownerField: '_id' }) + ] +}; + +exports.after = { + all: [hooks.remove('password')], + find: [], + get: [], + create: [], + update: [], + patch: [], + remove: [] +}; diff --git a/examples/with-featherjs/src/services/user/index.js b/examples/with-featherjs/src/services/user/index.js new file mode 100644 index 0000000000..b3c4e89a42 --- /dev/null +++ b/examples/with-featherjs/src/services/user/index.js @@ -0,0 +1,35 @@ +'use strict'; + +const path = require('path'); +const NeDB = require('nedb'); +const service = require('feathers-nedb'); +const hooks = require('./hooks'); + +module.exports = function(){ + const app = this; + + const db = new NeDB({ + filename: path.join(app.get('nedb'), 'users.db'), + autoload: true + }); + + let options = { + Model: db, + paginate: { + default: 5, + max: 25 + } + }; + + // Initialize our service with any options it requires + app.use('/users', service(options)); + + // Get our initialize service to that we can bind hooks + const userService = app.service('/users'); + + // Set up our before hooks + userService.before(hooks.before); + + // Set up our after hooks + userService.after(hooks.after); +}; diff --git a/examples/with-featherjs/static/favicon.ico b/examples/with-featherjs/static/favicon.ico new file mode 100644 index 0000000000..7ed25a60b0 Binary files /dev/null and b/examples/with-featherjs/static/favicon.ico differ diff --git a/examples/with-featherjs/test/app.test.js b/examples/with-featherjs/test/app.test.js new file mode 100644 index 0000000000..211eebcad4 --- /dev/null +++ b/examples/with-featherjs/test/app.test.js @@ -0,0 +1,38 @@ +'use strict'; + +const assert = require('assert'); +const request = require('request'); +const app = require('../src/app'); + +describe('Feathers application tests', function() { + before(function(done) { + this.server = app.listen(3030); + this.server.once('listening', () => done()); + }); + + after(function(done) { + this.server.close(done); + }); + + it('starts and shows the index page', function(done) { + request('http://localhost:3030', function(err, res, body) { + assert.ok(body.indexOf('

Welcome!

') !== -1); + done(err); + }); + }); + + describe('404', function() { + it('shows a 404 HTML page', function(done) { + request({ + url: 'http://localhost:3030/path/to/nowhere', + headers: { + 'Accept': 'text/html' + } + }, function(err, res, body) { + assert.equal(res.statusCode, 404); + assert.ok(body.indexOf('This page could not be found.') !== -1); + done(err); + }); + }); + }); +}); diff --git a/examples/with-featherjs/test/services/user/index.test.js b/examples/with-featherjs/test/services/user/index.test.js new file mode 100644 index 0000000000..a43dcaef23 --- /dev/null +++ b/examples/with-featherjs/test/services/user/index.test.js @@ -0,0 +1,10 @@ +'use strict'; + +const assert = require('assert'); +const app = require('../../../src/app'); + +describe('user service', function() { + it('registered the users service', () => { + assert.ok(app.service('users')); + }); +});