From 38884de64927d8e8a0bea141442d8ee6ca9afe16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Thu, 5 Dec 2024 11:17:30 +0100 Subject: [PATCH] feature/Add commit id info --- package.json | 2 +- server/app.ts | 16 +++++++++++++++- server/controllers/StatusController.ts | 8 +++++--- src/components/Preview.vue | 2 +- src/obp/common-functions.ts | 13 +++++++------ src/views/APIServerStatusView.vue | 7 ++++--- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 912cfda..4d6dd57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "api-explorer", - "version": "1.0.27", + "version": "1.0.28", "private": true, "scripts": { "dev": "vite & ts-node server/app.ts", diff --git a/server/app.ts b/server/app.ts index 46e3ba6..b5aefb5 100644 --- a/server/app.ts +++ b/server/app.ts @@ -34,6 +34,7 @@ import express, { Application } from 'express' import { useExpressServer, useContainer } from 'routing-controllers' import { Container } from 'typedi' import path from 'path' +import { execSync } from 'child_process'; const port = 8085 const app: Application = express() @@ -108,7 +109,6 @@ useContainer(Container) const routePrefix = '/api' const server = useExpressServer(app, { - //routePrefix: '/api/v1', routePrefix: routePrefix, controllers: [path.join(__dirname + '/controllers/*.*s')], middlewares: [path.join(__dirname + '/middlewares/*.*s')] @@ -120,4 +120,18 @@ console.log( `Backend is running. You can check a status at http://localhost:${port}${routePrefix}/status` ) +// Get commit ID +export const commitId = execSync('git rev-parse HEAD').toString().trim(); +console.log('Current Commit ID:', commitId); + +// Error Handling to Shut Down the App +server.on('error', (err) => { + if (err.code === 'EADDRINUSE') { + console.error(`Port ${port} is already in use.`); + process.exit(1); // Shut down the app + } else { + console.error('An error occurred:', err); + } +}); + export default app diff --git a/server/controllers/StatusController.ts b/server/controllers/StatusController.ts index 0e05516..0b6739d 100644 --- a/server/controllers/StatusController.ts +++ b/server/controllers/StatusController.ts @@ -31,6 +31,7 @@ import OBPClientService from '../services/OBPClientService' import OauthInjectedService from '../services/OauthInjectedService' import { Service } from 'typedi' import { OAuthConfig } from 'obp-typescript' +import { commitId } from '../app' @Service() @Controller('/status') @@ -60,9 +61,10 @@ export class StatusController { const resourceDocs = await this.checkResourceDocs(oauthConfig, version) return response.json({ status: apiVersions && messageDocs && resourceDocs, - apiVersions, - messageDocs, - resourceDocs + api_version: apiVersions, + message_docs: messageDocs, + resource_docs: resourceDocs, + commit_id: commitId }) } diff --git a/src/components/Preview.vue b/src/components/Preview.vue index 76e730a..396b0be 100644 --- a/src/components/Preview.vue +++ b/src/components/Preview.vue @@ -263,7 +263,7 @@ const copyToClipboard = () => {
-
{{ responseHeaderTitle }}:
+      
{{ responseHeaderTitle }}:
         
           
diff --git a/src/obp/common-functions.ts b/src/obp/common-functions.ts index a5f7499..8f6d35d 100644 --- a/src/obp/common-functions.ts +++ b/src/obp/common-functions.ts @@ -44,23 +44,24 @@ export function updateLoadingInfoMessage(logMessage: string) { } export function updateServerStatus() { - const oElem = document.getElementById('backend-status') + const oElem = document.getElementById('backend-status'); serverStatus() .then((body) => { if (oElem) { - Object.values(body).every((i) => i === true) + body.status === true ? (oElem.className = 'server-is-online') - : (oElem.className = 'server-is-offline') + : (oElem.className = 'server-is-offline'); } }) .catch((error) => { - console.log(error) + console.error(error); if (oElem) { - oElem.className = 'server-is-offline' + oElem.className = 'server-is-offline'; } - }) + }); } + export async function getCacheStorageInfo() { const message = await navigator.storage.estimate().then((estimate) => { const percent = ((estimate.usage / estimate.quota) * 100).toFixed(2) diff --git a/src/views/APIServerStatusView.vue b/src/views/APIServerStatusView.vue index c36fb1e..b3fb830 100644 --- a/src/views/APIServerStatusView.vue +++ b/src/views/APIServerStatusView.vue @@ -39,7 +39,7 @@ onBeforeMount(async () => {