From e2880c522c6b2e832fa757818824bd155a96eb8b Mon Sep 17 00:00:00 2001 From: Bernard Wolff <2744510+bernardwolff@users.noreply.github.com> Date: Thu, 19 Dec 2024 13:47:39 -0500 Subject: [PATCH] revert server/index.js --- server/index.js | 83 ++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/server/index.js b/server/index.js index a26142ac..bdc5d0ae 100644 --- a/server/index.js +++ b/server/index.js @@ -1,8 +1,8 @@ /* eslint-disable global-require */ const path = require('path'); -const Hapi = require('@hapi/hapi'); -const Inert = require('@hapi/inert'); +const Hapi = require('@auth0/hapi'); +const Inert = require('inert'); const jwt = require('hapi-auth-jwt2'); const config = require('../lib/config'); const logger = require('../lib/logger'); @@ -10,60 +10,65 @@ const routes = require('./routes'); const defaultHandlers = require('./handlers'); const auth = require('./auth'); -const createServer = async (handlers = defaultHandlers) => { - const server = Hapi.server({ +const createServer = (cb, handlers = defaultHandlers) => { + const server = new Hapi.Server(); + + server.connection({ host: 'localhost', port: config('PORT'), routes: { cors: true, + validate: {}, files: { relativeTo: path.join(__dirname, '../public') } } }); - // Register plugins - await server.register([jwt, Inert]); + server.register([jwt, Inert], () => {}); - // Define routes - server.route([ - { - method: 'GET', - path: '/js/{file*}', - options: { auth: false }, - handler: { - directory: { - path: path.join(__dirname, '../public/js') - } + server.route({ + method: 'GET', + path: '/js/{file*}', + config: { auth: false }, + handler: { + directory: { + path: path.join(__dirname, '../public/js') } - }, - { - method: 'GET', - path: '/css/{file*}', - options: { auth: false }, - handler: { - directory: { - path: path.join(__dirname, '../public/css') - } + } + }); + + server.route({ + method: 'GET', + path: '/css/{file*}', + config: { auth: false }, + handler: { + directory: { + path: path.join(__dirname, '../public/css') } } - ]); + }); + + server.register([auth, handlers, routes], (err) => { + // Use the server logger. + logger.debug = (...args) => { + server.log(['debug'], args.join(' ')); + }; + logger.info = (...args) => { + server.log(['info'], args.join(' ')); + }; + logger.error = (...args) => { + server.log(['error'], args.join(' ')); + }; - // Register additional plugins and routes - await server.register([auth, handlers, routes]); + if (err) { + cb(err); + } - // Configure server logging - logger.debug = (...args) => { - server.log(['debug'], args.join(' ')); - }; - logger.info = (...args) => { - server.log(['info'], args.join(' ')); - }; - logger.error = (...args) => { - server.log(['error'], args.join(' ')); - }; + cb(null, server); + }); - return server; // Return the server instance directly + return server; }; module.exports = createServer;