@@ -8,7 +8,7 @@ const express = require('express');
88const cors = require ( 'cors' ) ;
99const cookieParser = require ( 'cookie-parser' ) ;
1010const bodyParser = require ( 'body-parser' ) ;
11- const { OpenApiValidator } = require ( 'express-openapi-validator' ) ;
11+ const OpenApiValidator = require ( 'express-openapi-validator' ) ;
1212const logger = require ( './logger' ) ;
1313const config = require ( './config' ) ;
1414
@@ -32,11 +32,11 @@ class ExpressServer {
3232 this . app . use ( express . json ( ) ) ;
3333 this . app . use ( express . urlencoded ( { extended : false } ) ) ;
3434 this . app . use ( cookieParser ( ) ) ;
35- //Simple test to see that the server is up and responding
35+ // Simple test to see that the server is up and responding
3636 this . app . get ( '/hello' , ( req , res ) => res . send ( `Hello World. path: ${ this . openApiPath } ` ) ) ;
37- //Send the openapi document *AS GENERATED BY THE GENERATOR*
37+ // Send the openapi document *AS GENERATED BY THE GENERATOR*
3838 this . app . get ( '/openapi' , ( req , res ) => res . sendFile ( ( path . join ( __dirname , 'api' , 'openapi.yaml' ) ) ) ) ;
39- //View the openapi document in a visual interface. Should be able to test from this page
39+ // View the openapi document in a visual interface. Should be able to test from this page
4040 this . app . use ( '/api-docs' , swaggerUI . serve , swaggerUI . setup ( this . schema ) ) ;
4141 this . app . get ( '/login-redirect' , ( req , res ) => {
4242 res . status ( 200 ) ;
@@ -46,30 +46,28 @@ class ExpressServer {
4646 res . status ( 200 ) ;
4747 res . json ( req . query ) ;
4848 } ) ;
49+ this . app . use (
50+ OpenApiValidator . middleware ( {
51+ apiSpec : this . openApiPath ,
52+ operationHandlers : path . join ( __dirname ) ,
53+ fileUploader : { dest : config . FILE_UPLOAD_PATH } ,
54+ } ) ,
55+ ) ;
4956 }
5057
5158 launch ( ) {
52- new OpenApiValidator ( {
53- apiSpec : this . openApiPath ,
54- operationHandlers : path . join ( __dirname ) ,
55- fileUploader : { dest : config . FILE_UPLOAD_PATH } ,
56- } ) . install ( this . app )
57- . catch ( e => console . log ( e ) )
58- . then ( ( ) => {
59- // eslint-disable-next-line no-unused-vars
60- this . app . use ( ( err , req , res , next ) => {
61- // format errors
62- res . status ( err . status || 500 ) . json ( {
63- message : err . message || err ,
64- errors : err . errors || '' ,
65- } ) ;
66- } ) ;
67-
68- http . createServer ( this . app ) . listen ( this . port ) ;
69- console . log ( `Listening on port ${ this . port } ` ) ;
59+ // eslint-disable-next-line no-unused-vars
60+ this . app . use ( ( err , req , res , next ) => {
61+ // format errors
62+ res . status ( err . status || 500 ) . json ( {
63+ message : err . message || err ,
64+ errors : err . errors || '' ,
7065 } ) ;
71- }
66+ } ) ;
7267
68+ http . createServer ( this . app ) . listen ( this . port ) ;
69+ console . log ( `Listening on port ${ this . port } ` ) ;
70+ }
7371
7472 async close ( ) {
7573 if ( this . server !== undefined ) {
0 commit comments