import path from 'path';
import { Application } from 'express';
import { App, Initializer } from '@BridgemanAccessible/ba-web-framework';
import { PointerServer } from '@BridgemanAccessible/ba-auth';

const domain = process.env.DOMAIN || 'localhost';

/**
 * Callback for when the app starts.
 * 
 * @param app The Express app that gets created/started.
 */
function onStart(app: App) {
    // Currently within the Server class implementation,
    // which is then implemented by the accounts dashboard, 
    // only the RFC8414 path/callback is setup by default 
    // 
    // this should be easy enough to change but don't want to fiddle with it right now
    //const oidcLink = PointerServer.createOIDCLink('account.bridgemanaccessible.ca');
    const rfc8414Link = PointerServer.createRFC8414Link('account.bridgemanaccessible.ca');
    PointerServer.setup(app.getExpressApp(), { links: [/*oidcLink, */rfc8414Link] });
    app.getInitializer().getRouter().addOutsideFrameworkRoute('/.well-known/webfinger');
}

async function main() {
    await (new App()).run(new Initializer({
        controllersPath: path.resolve(__dirname, 'routes'),
        staticFilesPath: path.resolve(__dirname, 'static'),
        view: {
            filesPath: path.resolve(__dirname, 'pages')
        }
    }), onStart);
}

main();