0

How Can Change SwaggerPath Dynamically to severname, Down I have Given Swagger Options and Sever with Plugins.

/** ******************** swagger Options*********************** */ const swaggerOptions: HapiSwagger.RegisterOptions = { info: { title: 'Demo API', version: Pack.version, description, }, schemes: \['https', 'http'\], grouping: 'tags', sortEndpoints: 'ordered', documentationPath: "/api/v1/docs, basePath: "/api/v1", jsonPath:/api/v1/json, swaggerUIPath: /api/v1/swaggerUI`, pathPrefixSize: '/api/v1/docs'.length, payloadType: 'json', securityDefinitions: { jwt: { type: 'apiKey', name: 'Authorization', in: 'header', 'x-keyPrefix': 'Bearer ', }, }, security: [{ jwt: [] }], // Without this, the Authorization headers are never sent, but with them they are! };

//************************** HAPI SERVER ********************************//
const init = async () => {
/** ***********************Create a server************************ */

const server: any = Hapi.server({
port: 4040,
host: 'localhost',
routes: {
cors: true,
},
});
await server.register(Plugins);
await server.start();
};
init();
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Plugins**********//
/** **Import Module*** \*/
import \* as Hapi from '@hapi/hapi';
import \* as Inert from '@hapi/inert';
import \* as Vision from '@hapi/vision';
import \* as HapiSwagger from 'hapi-swagger';

/\*\* \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Import options \*\*\*\*\*\*\*\*\*\*\*\*\**/
import swaggerOptions from '../config/options/swaggerOptions';
import statusMonitor from '../config/options/statusMonitor';

/\*\* \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Plugin \*\*\*\*\*\*\*\*\*\*\*\*\\*/
const plugins: Array\<Hapi.ServerRegisterPluginObject\<any\>\> = \[
{
plugin: Inert,
},
{
plugin: Vision,
},
{
plugin: HapiSwagger,
options: swaggerOptions,
},
];

/** ******************** Export All *********************** */. 
export default plugins;  `

I need to configure with https scheme with my server domain name how Can do that i.e( for Example My server is running at Domain Name then my swagger is running in My server name But My server is running localhost So that My server Point out the localhost Not the Domain When Try run My swagger in server name )

0 Answers0