Skip to content

Commit bb700b5

Browse files
committed
mashlib was not loading and server OIDC listening issue
1 parent c65a248 commit bb700b5

File tree

6 files changed

+194
-191
lines changed

6 files changed

+194
-191
lines changed

lib/api/authn/webid-oidc.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export function initialize (app, argv) {
3131
const oidc = fromServerConfig(argv)
3232
app.locals.oidc = oidc
3333

34-
// Initialize OIDC provider (async)
35-
// Store the promise so the server can await it before listening
36-
app.locals.initPromise = oidc.initialize()
34+
// Store initialization function to be called after server starts listening
35+
// (OIDC client registration needs the server to be up to fetch openid-configuration)
36+
app.locals.initFunction = () => oidc.initialize()
3737

3838
// Attach the OIDC API
3939
app.use('/', middleware(oidc))

lib/create-app.mjs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// import { createRequire } from 'module'
2-
// const require = createRequire(import.meta.url)
31
import express from 'express'
42
import session from 'express-session'
53
import handlebars from 'express-handlebars'
@@ -89,7 +87,7 @@ function createApp (argv = {}) {
8987

9088
// Serve the public 'common' directory (for shared CSS files, etc)
9189
app.use('/common', express.static(path.join(__dirname, '../common')))
92-
app.use('/', express.static(path.dirname(import.meta.resolve('mashlib/dist/databrowser.html')), { index: false }))
90+
app.use('/', express.static(path.dirname(fileURLToPath(import.meta.resolve('mashlib/dist/databrowser.html'))), { index: false }))
9391
routeResolvedFile(app, '/common/js/', 'solid-auth-client/dist-lib/solid-auth-client.bundle.js')
9492
routeResolvedFile(app, '/common/js/', 'solid-auth-client/dist-lib/solid-auth-client.bundle.js.map')
9593
app.use('/.well-known', express.static(path.join(__dirname, '../common/well-known')))
@@ -331,13 +329,14 @@ function isLogoutRequest (req) {
331329
*
332330
* @param app {Object} Express.js app instance
333331
* @param argv {Object} Config options hashmap
332+
* @return {Promise} Resolves when authentication initialization is complete
334333
*/
335-
function initAuthentication (app, argv) {
334+
async function initAuthentication (app, argv) {
336335
const auth = argv.forceUser ? 'forceUser' : argv.auth
337336
if (!(auth in API.authn)) {
338337
throw new Error(`Unsupported authentication scheme: ${auth}`)
339338
}
340-
API.authn[auth].initialize(app, argv)
339+
await API.authn[auth].initialize(app, argv)
341340
}
342341

343342
/**

lib/create-server.mjs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,23 @@ function createServer (argv, app) {
100100
ldpApp.locals.ldp.live = solidWs.publish.bind(solidWs)
101101
}
102102

103-
// Wrap server.listen() to ensure async initialization completes first
103+
// Wrap server.listen() to ensure async initialization completes after server starts
104104
const originalListen = server.listen.bind(server)
105105
server.listen = function (...args) {
106-
if (ldpApp.locals.initPromise) {
107-
const initPromise = ldpApp.locals.initPromise
108-
delete ldpApp.locals.initPromise
109-
110-
// Wait for initialization, then start listening
111-
initPromise
112-
.then(() => originalListen(...args))
113-
.catch(err => server.emit('error', err))
114-
} else {
115-
originalListen(...args)
106+
// Start listening first
107+
originalListen(...args)
108+
109+
// Then run async initialization (if needed)
110+
if (ldpApp.locals.initFunction) {
111+
const initFunction = ldpApp.locals.initFunction
112+
delete ldpApp.locals.initFunction
113+
114+
// Run initialization after server is listening
115+
initFunction()
116+
.catch(err => {
117+
console.error('Initialization error:', err)
118+
server.emit('error', err)
119+
})
116120
}
117121

118122
return server

lib/utils.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import path from 'path'
55
import util from 'util'
66
import $rdf from 'rdflib'
77
import from from 'from2'
8-
import url from 'url'
8+
import url, { fileURLToPath } from 'url'
99
import debugModule from './debug.mjs'
1010
import getSize from 'get-folder-size'
1111
import vocab from 'solid-namespace'
@@ -237,7 +237,7 @@ export function stripLineEndings (obj) {
237237
*/
238238
export function routeResolvedFile (router, path, file, appendFileName = true) {
239239
const fullPath = appendFileName ? path + file.match(/[^/]+$/) : path
240-
const fullFile = import.meta.resolve(file)
240+
const fullFile = fileURLToPath(import.meta.resolve(file))
241241
router.get(fullPath, (req, res) => res.sendFile(fullFile))
242242
}
243243

0 commit comments

Comments
 (0)