Skip to content

Commit

Permalink
feat: add version to startup logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sct committed Dec 16, 2020
1 parent df4ac83 commit 2948f93
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 3 additions & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import { startJobs } from './job/schedule';
import notificationManager from './lib/notifications';
import DiscordAgent from './lib/notifications/agents/discord';
import EmailAgent from './lib/notifications/agents/email';
import { getAppVersion } from './utils/appVersion';

const API_SPEC_PATH = path.join(__dirname, '../overseerr-api.yml');

logger.info(`Starting Overseerr version ${getAppVersion()}`);
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
Expand Down Expand Up @@ -101,7 +103,7 @@ app
const port = Number(process.env.PORT) || 3000;
server.listen(port, () => {
logger.info(`Server ready on port ${port}`, {
label: 'SERVER',
label: 'Server',
});
});
})
Expand Down
11 changes: 2 additions & 9 deletions server/routes/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { isAuthenticated } from '../middleware/auth';
import { merge } from 'lodash';
import Media from '../entity/Media';
import { MediaRequest } from '../entity/MediaRequest';
import { getAppVersion } from '../utils/appVersion';

const settingsRoutes = Router();

Expand Down Expand Up @@ -445,16 +446,8 @@ settingsRoutes.get('/about', async (req, res) => {
const totalMediaItems = await mediaRepository.count();
const totalRequests = await mediaRequestRepository.count();

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version } = require('../../package.json');

let finalVersion = version;

if (version === '0.1.0') {
finalVersion = `develop-${process.env.COMMIT_TAG ?? 'local'}`;
}
return res.status(200).json({
version: finalVersion,
version: getAppVersion(),
totalMediaItems,
totalRequests,
});
Expand Down
12 changes: 12 additions & 0 deletions server/utils/appVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const getAppVersion = (): string => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version } = require('../../package.json');

let finalVersion = version;

if (version === '0.1.0') {
finalVersion = `develop-${process.env.COMMIT_TAG ?? 'local'}`;
}

return finalVersion;
};

0 comments on commit 2948f93

Please sign in to comment.