express-user-manager
express-user-manager copied to clipboard
Can't add other services to the same app after initialization of express-user-manager
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}/`)
})
})
Commenting following line in login.js did the job, but it worth investigating further.
//hooks.execute('response', generateRoute(routeKeys.login), req, res, next)