feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 742 forks source link

Register multiple Express middleware functions #3463

Closed DowsingUK closed 1 month ago

DowsingUK commented 2 months ago

I could achieve this on FeathersJS v4 using this code:

const { Test } = require('./test.class');

app.use(
    '/test',
    (req, res, next) => {
      res.data = 'Step 1 worked'
      next()
    },
    new Test(options, app), // THIS JUST WORKS 
    (req, res) => {
      res.json({
        message: Hello world from Express middleware ${res.data}
      })
    },
  )

Now I have no idea how to achieve the same on FeathersJS V5

  import { TestService, getOptions } from './test.class'
  import { appUploadsPath, appUploadsMethods } from './app-uploads.shared'

  app.use(
    testPath,
    (req, res, next) => {
      res.data = 'Step 1 worked'
      next()
    },
    new TestService(getOptions(app)), // THIS IS NOT WORKING AT ALL 
    (req, res) => {
      res.json({
        message: Hello world from Express middleware ${res.data}
      })
    },
  )

Thanks for your help.

DowsingUK commented 2 months ago
import { TestService, getOptions } from './test.class'
  import { appUploadsPath, appUploadsMethods } from './app-uploads.shared'

  app.use(
    testPath,
    (req, res, next) => {
      res.data = 'Step 1 worked'
      next()
    },
    new TestService(getOptions(app)) as any, // THIS IS WORKING NOW 
    (req, res) => {
      res.json({
        message: Hello world from Express middleware ${res.data}
      })
    },
  )