From edee7d8613b5b06aeb9f3e557ddf0d5a1abbdf1e Mon Sep 17 00:00:00 2001 From: Kasra Bigdeli Date: Wed, 3 Dec 2025 22:59:41 -0800 Subject: [PATCH] Fixed issue raised in https://github.com/caprover/caprover/pull/2362\#issuecomment-3609213641 --- src/routes/user/system/SystemRouter.ts | 40 +++++++++++++++++--------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/routes/user/system/SystemRouter.ts b/src/routes/user/system/SystemRouter.ts index 1fc799d..351bdbd 100644 --- a/src/routes/user/system/SystemRouter.ts +++ b/src/routes/user/system/SystemRouter.ts @@ -474,21 +474,33 @@ router.get('/goaccess/:appName/files/:file', async function (req, res, next) { }) } - const path = `${appName}/${file}` - res.sendFile( - path, - { root: CaptainConstants.nginxSharedLogsPathOnHost }, - function (error) { - if (error !== undefined) { - Logger.e(error, 'Error getting GoAccess report ' + path) - const baseApi = new BaseApi( - ApiStatusCodes.NOT_FOUND, - 'Report not found' - ) - res.send(baseApi) - } - } + const fileRelativePath = `${appName}/${file}` + const absolutePath = path.join( + CaptainConstants.nginxSharedLogsPathOnHost, + appName, + file ) + + return Promise.resolve() + .then(function () { + return fs.readFile(absolutePath, 'utf8') + }) + .then(function (fileContents) { + const baseApi = new BaseApi( + ApiStatusCodes.STATUS_OK, + 'GoAccess report retrieved' + ) + baseApi.data = fileContents + res.send(baseApi) + }) + .catch(function (error) { + Logger.e(error, 'Error getting GoAccess report ' + fileRelativePath) + const baseApi = new BaseApi( + ApiStatusCodes.NOT_FOUND, + 'Report not found' + ) + res.send(baseApi) + }) }) router.get('/nginxconfig/', function (req, res, next) {