Skip to content

Commit

Permalink
feat: add a trailing slash redirect in docs path
Browse files Browse the repository at this point in the history
use "joi" package instead of deprecated "@hapi/joi"
  • Loading branch information
mo4islona committed Aug 12, 2021
1 parent e57d37b commit 8536041
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 186 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nestjs-redoc",
"version": "2.2.2",
"version": "2.2.4",
"description": "NestJS ReDoc frontend",
"repository": "https://github.com/mxarc/nestjs-redoc",
"author": "Alfonso Reyes",
Expand All @@ -25,10 +25,10 @@
"@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0",
"@nestjs/swagger": "^5.0.0",
"reflect-metadata": "^0.1.12"
"reflect-metadata": "^0.1.13"
},
"dependencies": {
"@hapi/joi": "^17.1.1",
"joi": "^17.4.2",
"@nestjs/common": "^8.0.0",
"@nestjs/swagger": "^5.0.0",
"express-basic-auth": "^1.2.0",
Expand All @@ -43,7 +43,7 @@
"@nestjs/testing": "^8.0.0",
"@types/express": "^4.17.8",
"@types/express-handlebars": "^3.1.0",
"@types/hapi__joi": "^17.1.6",
"@types/joi": "^17.2.3",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.6",
"@types/supertest": "^2.0.10",
Expand All @@ -58,7 +58,7 @@
"prettier": "^2.1.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.6.3",
"rxjs": "^7.3.0",
"supertest": "^6.0.1",
"ts-jest": "^26.4.3",
"ts-node": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/model/options.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Joi = require('@hapi/joi');
import Joi = require('joi');
import { OpenAPIObject } from '@nestjs/swagger';

export const schema = (document: OpenAPIObject) =>
Expand Down
9 changes: 8 additions & 1 deletion src/redoc-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import handlebars from 'express-handlebars';
import pathModule from 'path';
import { resolve } from 'url';
import { LogoOptions, RedocDocument, RedocOptions } from './interfaces';
import { schema } from './model/options.model';
import { schema } from './model';

export class RedocModule {
/**
Expand Down Expand Up @@ -121,10 +121,16 @@ export class RedocModule {
'views',
'redoc.handlebars'
);

// get handlebars rendered HTML
const redocHTML = await hbs.render(redocFilePath, renderData);
// Serve ReDoc Frontend
httpAdapter.get(finalPath, async (req: Request, res: Response) => {
if (!req.url.endsWith('/')) {
res.redirect(301, req.url + '/');
return;
}

const sendPage = () => {
// Content-Security-Policy: worker-src 'self' blob:
res.setHeader(
Expand All @@ -147,6 +153,7 @@ export class RedocModule {
sendPage();
}
});

// Serve swagger spec json
httpAdapter.get(docUrl, (req: Request, res: Response) => {
res.setHeader('Content-Type', 'application/json');
Expand Down
Loading

0 comments on commit 8536041

Please sign in to comment.