Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions lib/create-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,32 @@ function createServer (argv, app) {
// Wrap server.listen() to ensure async initialization completes after server starts
const originalListen = server.listen.bind(server)
server.listen = function (...args) {
// Start listening first
originalListen(...args)
const lastArg = args[args.length - 1]
const hasCallback = typeof lastArg === 'function'
const readyCallback = hasCallback ? lastArg : null

// Then run async initialization (if needed)
if (ldpApp.locals.initFunction) {
if (hasCallback) {
args = args.slice(0, -1)
}

originalListen(...args, () => {
const initFunction = ldpApp.locals.initFunction
delete ldpApp.locals.initFunction

// Run initialization after server is listening
if (!initFunction) {
if (readyCallback) readyCallback()
return
}

initFunction()
.then(() => {
if (readyCallback) readyCallback()
})
.catch(err => {
console.error('Initialization error:', err)
server.emit('error', err)
})
}
})

return server
}
Expand Down
28 changes: 14 additions & 14 deletions test/integration/www-account-creation-oidc-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,13 @@ describe('AccountManager (OIDC account creation tests)', function () {
})

// FIXME: #1502
describe('Single User signup page', () => {
const serverUri = 'https://localhost:7457'
const port = 7457
let ldpHttpsServer
rm('resources/accounts/single-user/')
const rootDir = path.normalize(path.join(__dirname, '../resources/accounts/single-user/'))
const configPath = path.normalize(path.join(__dirname, '../resources/config'))
const ldp = ldnode.createServer({
describe('Single User signup page', () => {
const serverUri = 'https://localhost:7457'
const port = 7457
let ldpHttpsServer
const rootDir = path.normalize(path.join(__dirname, '../resources/accounts/single-user/'))
const configPath = path.normalize(path.join(__dirname, '../resources/config'))
const ldp = ldnode.createServer({
port,
root: rootDir,
configPath,
Expand All @@ -244,12 +243,13 @@ describe('Single User signup page', () => {
multiuser: false,
strictOrigin: true
})
const server = supertest(serverUri)

before(function (done) {
ldpHttpsServer = ldp.listen(port, () => server.post('/api/accounts/new')
.send('username=foo&password=12345&acceptToc=true')
.end(done))
const server = supertest(serverUri)

before(function (done) {
fs.removeSync(rootDir)
ldpHttpsServer = ldp.listen(port, () => server.post('/api/accounts/new')
.send('username=foo&password=12345&acceptToc=true')
.end(done))
})

after(function () {
Expand Down