diff --git a/src/index.ts b/src/index.ts index 6666d96..902dc17 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,8 +81,9 @@ const ncrApp = async () => { .get(config.openapiPath, (res) => { res.writeStatus('200 OK').writeHeader('Content-Type', 'text/html').end(openapiTemplate); }) - .get('/oas.json', async (res) => { + .get('/oas.json', async (res, req) => { definition.paths = {}; + const hostPath = `http://${req.getHeader('host')}${config.basepath}`; const tags: string[] = []; await Promise.all( Dir.files.map(async (endpoints) => { @@ -98,7 +99,10 @@ const ncrApp = async () => { metadata ); definition.paths[prefixedPath + '/raw'] = generateRawPath(); - definition.paths[prefixedPath + '/app'] = generateAppletPath(); + + definition.paths[prefixedPath + '/app'] = generateAppletPath( + hostPath + prefixedPath + '/app' + ); } }) ); diff --git a/src/openapi.ts b/src/openapi.ts index 7584838..c882db9 100644 --- a/src/openapi.ts +++ b/src/openapi.ts @@ -28,13 +28,13 @@ export function generateRawPath(): OpenAPIV3_1.PathItemObject { }; } -export function generateAppletPath(): OpenAPIV3_1.PathItemObject { +export function generateAppletPath(appletUrl: string): OpenAPIV3_1.PathItemObject { return { get: { tags: [defaultTagsName.applet], responses: { '200': { - description: 'Generated applet on the fly based on the contract introspection', + description: `[👉 Click here to open the applet](${appletUrl})`, content: { 'text/html': { schema: Type.String() } } } }