Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 2b763c9

Browse files
Merge pull request #87 from Human-Connection/upgrade-to-feathers-v3
[WIP] Upgrade to feathers v3
2 parents 121c4e4 + 0ee9e3f commit 2b763c9

File tree

81 files changed

+1056
-1098
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1056
-1098
lines changed

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252
"concurrently": "concurrently --kill-others --success first"
5353
},
5454
"dependencies": {
55+
"@feathersjs/authentication": "^2.1.7",
56+
"@feathersjs/authentication-jwt": "^2.0.1",
57+
"@feathersjs/authentication-local": "^1.2.1",
58+
"@feathersjs/configuration": "^1.0.2",
59+
"@feathersjs/errors": "^3.3.0",
60+
"@feathersjs/express": "^1.2.3",
61+
"@feathersjs/feathers": "^3.1.7",
62+
"@feathersjs/socketio": "^3.2.2",
5563
"body-parser": "~1.18.3",
5664
"cheerio": "^1.0.0-rc.2",
5765
"compression": "~1.7.2",
@@ -60,27 +68,18 @@
6068
"crypto-js": "^3.1.9-1",
6169
"dauria": "~2.0.0",
6270
"email-templates": "2.6.0",
63-
"feathers": "~2.2.4",
64-
"feathers-authentication": "~1.3.1",
65-
"feathers-authentication-hooks": "~0.1.6",
66-
"feathers-authentication-jwt": "~0.3.2",
67-
"feathers-authentication-local": "~0.4.4",
68-
"feathers-authentication-management": "~1.0.3",
69-
"feathers-blob": "~1.3.1",
70-
"feathers-configuration": "~0.4.2",
71-
"feathers-errors": "~2.9.2",
72-
"feathers-hooks": "~2.1.2",
73-
"feathers-hooks-common": "~3.10.0",
74-
"feathers-logger": "0.2.3",
71+
"feathers-authentication-hooks": "~0.3.0",
72+
"feathers-authentication-management": "~2.0.0",
73+
"feathers-blob": "~2.0.1",
74+
"feathers-hooks-common": "~4.14.0",
75+
"feathers-logger": "0.3.2",
7576
"feathers-mailer": "~2.0.0",
76-
"feathers-memory": "~1.3.1",
77-
"feathers-mongodb": "~3.0.0",
77+
"feathers-memory": "~2.1.3",
78+
"feathers-mongodb": "~3.2.0",
7879
"feathers-mongodb-fuzzy-search": "~1.1.1",
79-
"feathers-mongoose": "~5.1.2",
80+
"feathers-mongoose": "~6.1.2",
8081
"feathers-profiler": "^0.1.5",
81-
"feathers-rest": "~1.8.1",
8282
"feathers-seeder": "~1.0.10",
83-
"feathers-socketio": "~2.0.1",
8483
"fs-blob-store": "~5.2.1",
8584
"fs-extra": "~4.0.2",
8685
"handlebars": "~4.0.11",
@@ -112,6 +111,7 @@
112111
"istanbul": "1.1.0-alpha.1",
113112
"mocha": "~5.2.0",
114113
"nodemon": "~1.17.4",
114+
"nyc": "^12.0.2",
115115
"wait-on": "~2.1.0"
116116
}
117117
}

server/app.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ const cors = require('cors');
55
// const helmet = require('helmet');
66
const bodyParser = require('body-parser');
77

8-
const feathers = require('feathers');
9-
const configuration = require('feathers-configuration');
10-
const hooks = require('feathers-hooks');
11-
const rest = require('feathers-rest');
12-
const socketio = require('feathers-socketio');
8+
const feathers = require('@feathersjs/feathers');
9+
const express = require('@feathersjs/express');
10+
const configuration = require('@feathersjs/configuration');
11+
const rest = require('@feathersjs/express/rest');
12+
const socketio = require('@feathersjs/socketio');
1313
const seeder = require('./seeder');
14+
const channels = require('./channels');
1415

1516
const middleware = require('./middleware');
1617
const services = require('./services');
@@ -21,7 +22,7 @@ const Raven = require('raven');
2122
const logger = require('./logger');
2223
const { profiler } = require('feathers-profiler');
2324

24-
const app = feathers();
25+
const app = express(feathers());
2526

2627
app.configure(require('feathers-logger')(logger));
2728

@@ -49,10 +50,8 @@ app.use(bodyParser.json());
4950
app.use(bodyParser.urlencoded({ extended: true }));
5051
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
5152
// Host the public folder
52-
app.use('/', feathers.static(app.get('public')));
53+
app.use('/', express.static(app.get('public')));
5354

54-
// Set up Plugins and providers
55-
app.configure(hooks());
5655
app.configure(mongoose);
5756
app.configure(rest());
5857

@@ -65,6 +64,7 @@ app.configure(authentication);
6564

6665
// Set up our services (see `services/index.js`)
6766
app.configure(services);
67+
app.configure(channels);
6868

6969
if (process.env.NODE_ENV !== 'production') {
7070
app.configure(profiler({

server/authentication.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const authentication = require('feathers-authentication');
2-
const jwt = require('feathers-authentication-jwt');
3-
const local = require('feathers-authentication-local');
1+
const authentication = require('@feathersjs/authentication');
2+
const jwt = require('@feathersjs/authentication-jwt');
3+
const local = require('@feathersjs/authentication-local');
44
const { lowerCase } = require('feathers-hooks-common');
55

66
module.exports = function () {

server/channels.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
module.exports = function (app) {
2+
if (typeof app.channel !== 'function') {
3+
// If no real-time functionality has been configured just return
4+
return;
5+
}
6+
7+
app.on('connection', connection => {
8+
// On a new real-time connection, add it to the anonymous channel
9+
app.channel('anonymous').join(connection);
10+
});
11+
12+
app.on('login', (authResult, { connection }) => {
13+
// connection can be undefined if there is no
14+
// real-time connection, e.g. when logging in via REST
15+
if (connection) {
16+
// Obtain the logged in user from the connection
17+
const user = connection.user;
18+
19+
// The connection is no longer anonymous, remove it
20+
app.channel('anonymous').leave(connection);
21+
22+
// Add it to the authenticated user channel
23+
app.channel('authenticated').join(connection);
24+
25+
if (user.role === 'moderator') { app.channel('moderators').join(connection); }
26+
if (user.role === 'admin') { app.channel('admins').join(connection); }
27+
28+
// Channels can be named anything and joined on any condition
29+
30+
// E.g. to send real-time events only to admins use
31+
// if(user.isAdmin) { app.channel('admins').join(connection); }
32+
33+
// If the user has joined e.g. chat rooms
34+
// if(Array.isArray(user.rooms)) user.rooms.forEach(room => app.channel(`rooms/${room.id}`).join(channel));
35+
36+
// Easily organize users by email and userid for things like messaging
37+
// app.channel(`emails/${user.email}`).join(channel);
38+
// app.channel(`userIds/$(user.id}`).join(channel);
39+
}
40+
});
41+
42+
// app.publish((data, hook) => { // eslint-disable-line no-unused-vars
43+
// // Here you can add event publishers to channels set up in `channels.js`
44+
// // To publish only for a specific event use `app.publish(eventname, () => {})`
45+
// // e.g. to publish all service events to all authenticated users use
46+
// return app.channel('authenticated');
47+
// });
48+
49+
app.service('contributions').publish('patched', () => app.channel('authenticated'));
50+
51+
app.service('categories').publish(() => app.channel('anonymous', 'authenticated'));
52+
app.service('comments').publish(() => app.channel('authenticated'));
53+
app.service('follows').publish(() => app.channel('authenticated'));
54+
app.service('users-candos').publish(() => app.channel('authenticated'));
55+
app.service('notifications').publish(() => app.channel('authenticated'));
56+
app.service('system-notifications').publish(() => app.channel('authenticated'));
57+
58+
app.service('users').publish(() => app.channel('admins'));
59+
app.service('organizations').publish(() => app.channel('admins', 'moderators'));
60+
61+
// app.service('contributions').publish((data) => {
62+
// return [
63+
// // app.channel('anonymous'),
64+
// // app.channel('authenticated')
65+
// app.channel(`contributions/${data._id}`)
66+
// ];
67+
// });
68+
// app.service('contributions').publish((data) => {
69+
// return app.channel(`contributions/${data.slug}`);
70+
// });
71+
// app.service('comments').publish((data) => {
72+
// return app.channel(`contributions/${data.slug}`);
73+
// });
74+
75+
// Here you can also add service specific event publishers
76+
// e..g the publish the `users` service `created` event to the `admins` channel
77+
// app.service('users').publish('created', () => app.channel('admins'));
78+
79+
// With the userid and email organization from above you can easily select involved users
80+
// app.service('messages').publish(() => {
81+
// return [
82+
// app.channel(`userIds/${data.createdBy}`),
83+
// app.channel(`emails/${data.recipientEmail}`)
84+
// ];
85+
// });
86+
};

server/hooks/exclude-disabled.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Exclude items with isEnabled = false
2-
const errors = require('feathers-errors');
2+
const errors = require('@feathersjs/errors');
33

44
module.exports = function excludeDisabled() {
55
return function (hook) {

server/hooks/is-admin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Check if user is admin
2-
const errors = require('feathers-errors');
2+
const errors = require('@feathersjs/errors');
33

44
module.exports = () => hook => {
55
if(!hook.params || !hook.params.user || hook.params.user.role !== 'admin') {

server/hooks/is-enabled.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// For more information on hooks see: http://docs.feathersjs.com/api/hooks.html
33

44
const _ = require('lodash');
5-
const errors = require('feathers-errors');
5+
const errors = require('@feathersjs/errors');
66

77
module.exports = function isEnabled(options = {}) { // eslint-disable-line no-unused-vars
88
return function (hook) {

server/hooks/is-moderator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Check if user is moderator
2-
const errors = require('feathers-errors');
2+
const errors = require('@feathersjs/errors');
33

44
module.exports = () => hook => {
55
if(!hook.params || !hook.params.user || !['admin','moderator'].includes(hook.params.user.role)) {

server/hooks/restrictToOwnerOrModerator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { getByDot } = require('feathers-hooks-common');
2-
const errors = require('feathers-errors');
2+
const errors = require('@feathersjs/errors');
33

44
module.exports = function restrictToOwnerOrModerator (query = {}) { // eslint-disable-line no-unused-vars
55
return function (hook) {

server/middleware/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const handler = require('feathers-errors/handler');
1+
const handler = require('@feathersjs/express/errors');
22
const notFound = require('feathers-errors/not-found');
33

44
module.exports = function () {

0 commit comments

Comments
 (0)