Skip to content

Can't add other services to the same app after initialization of express-user-manager #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
antonioleoreply opened this issue May 21, 2022 · 1 comment

Comments

@antonioleoreply
Copy link

If I try to add other methods to the same app used by the module I receive this error:

(node:41104) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at new NodeError (internal/errors.js:322:7)
    at ServerResponse.setHeader (_http_outgoing.js:561:11)
    at ServerResponse.header (C:\Repositories\Obiwan\rona_core_tools\node_modules\express\lib\response.js:771:10)
    at ServerResponse.send (C:\Repositories\Obiwan\rona_core_tools\node_modules\express\lib\response.js:170:12)
    at ServerResponse.json (C:\Repositories\Obiwan\rona_core_tools\node_modules\express\lib\response.js:267:15)
    at login (C:\Repositories\Obiwan\rona_core_tools\server\express-user-manager\routes\handlers\login.js:81:30)

my code:

app.use(
  fileUpload({
    createParentPath: true,
  }),
)
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(morgan('dev'))
app.use(express.static(path.join(__dirname, '../build')))

const dbAdapter = 'mongoose'
const store = userManager.getDbAdapter(dbAdapter)
userManager.listen(app, (apiMountPoint = '/rest/users'), (customRoutes = {}))

app.get('/examplerequest', function (req, res) {
  res.send('example response')
})

store.connect(Mongo.mongoURI).then(() => {
  server.listen(port, () => {
    console.log(`Server running at http://localhost:${port}/`)
  })
})

@antonioleoreply
Copy link
Author

antonioleoreply commented May 21, 2022

Commenting following line in login.js did the job, but it worth investigating further.

 //hooks.execute('response', generateRoute(routeKeys.login), req, res, next)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant