Skip to content

Commit

Permalink
revert server/index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardwolff authored Dec 19, 2024
1 parent eee444b commit e2880c5
Showing 1 changed file with 44 additions and 39 deletions.
83 changes: 44 additions & 39 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,74 @@
/* 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');
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;

0 comments on commit e2880c5

Please sign in to comment.