feathersjs-ecosystem / feathers-sync

Synchronize service events between Feathers application instances
MIT License
221 stars 41 forks source link

TypeError: app.service(...).publish is not a function #131

Closed averri closed 4 years ago

averri commented 4 years ago

Steps to reproduce

Create a standard Feathers application using feathers-sync.

The following code snippet is where the problem occurs. There are no issues without using feathers-sync.

app.service('session-manager').publish('created', ({sessionId}) => {
    return app.channel(sessionId)
})

Expected behavior

It should be possible to use the method publish to publish events to specific channels.

Actual behavior

The application throws an exeption:

3|src    | TypeError: app.service(...).publish is not a function
3|src    |     at Function.module.exports (/home/alex/dev/src/other/strenux/strenux-api/src/services/config/session-manager.js:46:34)
3|src    |     at Function.configure (/home/alex/dev/src/other/strenux/strenux-api/node_modules/@feathersjs/feathers/lib/application.js:59:8)
3|src    |     at /home/alex/dev/src/other/strenux/strenux-api/src/services/index.js:44:9
3|src    |     at Array.forEach (<anonymous>)
3|src    |     at Function.module.exports (/home/alex/dev/src/other/strenux/strenux-api/src/services/index.js:42:9)
3|src    |     at Function.configure (/home/alex/dev/src/other/strenux/strenux-api/node_modules/@feathersjs/feathers/lib/application.js:59:8)
3|src    |     at Object.<anonymous> (/home/alex/dev/src/other/strenux/strenux-api/src/app.js:44:5)
3|src    |     at Module._compile (internal/modules/cjs/loader.js:759:30)
3|src    |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
3|src    |     at Module.load (internal/modules/cjs/loader.js:628:32)

The feathers-sync has been configured according to the documentation:

const sync = require('feathers-sync')

const redisURL = process.env.REDIS_URL || 'redis://localhost:6379'

module.exports = app => {
  app.configure(sync({
    uri: redisURL
}))

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working):

  "dependencies": {
    "@feathersjs/authentication": "^4.3.10",
    "@feathersjs/authentication-local": "^4.3.10",
    "@feathersjs/authentication-oauth": "^4.3.10",
    "@feathersjs/configuration": "^4.3.10",
    "@feathersjs/errors": "^4.3.10",
    "@feathersjs/express": "^4.3.10",
    "@feathersjs/feathers": "^4.3.10",
    "@feathersjs/socketio": "^4.3.10",
    "@hapi/joi": "15.1.1",
    "aqb": "^2.1.0",
    "arangojs": "^6.11.1",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "date-fns": "^2.6.0",
    "express-handlebars": "^3.1.0",
    "feathers-authentication-hooks": "^1.0.1",
    "feathers-hooks-common": "^4.20.7",
    "feathers-permissions": "^1.1.0",
    "feathers-sync": "^1.1.3",
    "glob": "^7.1.5",
    "helmet": "^3.20.0",
    "joi-errors-for-forms": "^0.2.6",
    "lodash": "^4.17.15",
    "nodemailer": "^6.3.1",
    "nodemailer-express-handlebars": "^3.1.0",
    "prom-client": "^11.5.3",
    "prometheus-api-metrics": "^2.2.3",
    "qrcode": "^1.4.2",
    "rate-limiter-flexible": "^1.1.6",
    "serve-favicon": "^2.5.0",
    "speakeasy": "^2.0.0",
    "stackimpact": "^1.3.21",
    "ua-parser-js": "^0.7.20",
    "uid-generator": "^2.0.0",
    "uuid": "^3.3.3",
    "winston": "^3.0.0"
  },

NodeJS version: 12.13.0

Operating System: Linux Ubuntu 18.04

Browser Version: Chrome

React Native Version: N/A

Module Loader: require

daffl commented 4 years ago

I can not reproduce this in the feathers-chat putting the initialization after app.configure(configuration());:

app.configure(configuration());
app.configure(sync({
  uri: 'redis://localhost:6379'
}));

And adding

app.service('messages').publish('created', data => app.channel('authenticated'));

To the configuration.

averri commented 4 years ago

Thanks for looking into that, @daffl.

I have managed to make the configuration to work. I have removed other components, hooks, simplified a lot until got it working. Some other component was interfering with the functionality.

I'll close it as it's not easily reproducible.