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) {