Skip to content

Commit

Permalink
feat: add swagger plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHardouin committed Jul 11, 2024
1 parent 0beba38 commit e43d6cf
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 18 deletions.
5 changes: 4 additions & 1 deletion lib/common/logger/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as pino from 'pino';
import { stdSerializers } from 'pino';
import * as pinoPretty from 'pino-pretty';

import { config } from '../config.js';
import { stdSerializers } from 'pino';

const { logging } = config;

let prettyPrint;
if (logging.logForHumans) {
const omitDay = 'HH:MM:ss';
// @ts-expect-error pino pretty does not have a named export
prettyPrint = pinoPretty.default({
sync: true,
colorize: true,
Expand All @@ -16,6 +18,7 @@ if (logging.logForHumans) {
});
}

// @ts-expect-error pino does not have a named export
export const logger = pino.default(
{
level: logging.logLevel,
Expand Down
5 changes: 0 additions & 5 deletions lib/common/logger/plugins/plugins.ts

This file was deleted.

7 changes: 7 additions & 0 deletions lib/infrastructure/plugins/plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Inert from '@hapi/inert';
import Vision from '@hapi/vision';

import * as pino from '../../common/logger/plugins/pino.js';
import { swaggerPlugin } from './swagger.js';

export const plugins = [Inert, Vision, pino, swaggerPlugin];
13 changes: 13 additions & 0 deletions lib/infrastructure/plugins/swagger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import HapiSwagger from 'hapi-swagger';

import packageJson from '../../../package.json' with { type: 'json' };

export const swaggerPlugin = {
plugin: HapiSwagger,
options: {
info: {
title: 'API Data Documentation',
version: packageJson.version,
},
},
};
5 changes: 3 additions & 2 deletions lib/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { routes } from './routes.js';
import Hapi, { Server, ServerOptions } from '@hapi/hapi';
import { plugins } from './common/logger/plugins/plugins.js';

import { authentication } from './infrastructure/authentication.js';
import { plugins } from './infrastructure/plugins/plugins.js';
import { routes } from './routes.js';

const createServer = async (): Promise<Server> => {
const server = createBareServer();
Expand Down
Loading

0 comments on commit e43d6cf

Please sign in to comment.