Skip to content

Commit

Permalink
rewrite companion.app() to return an object (transloadit#3827)
Browse files Browse the repository at this point in the history
with { app, emitter }
gives more flexibility in the future
  • Loading branch information
mifi committed Jun 27, 2022
1 parent bc91241 commit 4f69af2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -48,7 +48,8 @@ const options = {
filePath: '/path/to/folder/',
}

app.use(companion.app(options))
const { app: companionApp } = companion.app(options)
app.use(companionApp)
```

To enable companion socket for realtime feed to the client while upload is going on, you call the `socket` method like so.
Expand Down
7 changes: 2 additions & 5 deletions src/companion.js
Expand Up @@ -57,7 +57,7 @@ module.exports.socket = require('./server/socket')
* Entry point into initializing the Companion app.
*
* @param {object} optionsArg
* @returns {import('express').Express}
* @returns {{ app: import('express').Express, emitter: any }}}
*/
module.exports.app = (optionsArg = {}) => {
validateConfig(optionsArg)
Expand Down Expand Up @@ -152,8 +152,5 @@ module.exports.app = (optionsArg = {}) => {
processId,
})

// todo split emitter from app in next major
// @ts-ignore
app.companionEmitter = emitter
return app
return { app, emitter }
}
2 changes: 1 addition & 1 deletion src/standalone/index.js
Expand Up @@ -167,7 +167,7 @@ module.exports = function server (inputCompanionOptions = {}) {
}

// initialize companion
const companionApp = companion.app(companionOptions)
const { app: companionApp } = companion.app(companionOptions)

// add companion to server middleware
router.use(companionApp)
Expand Down

0 comments on commit 4f69af2

Please sign in to comment.