diff --git a/src/routes/main.js b/src/routes/main.js index 5f19067..6e9f988 100644 --- a/src/routes/main.js +++ b/src/routes/main.js @@ -31,7 +31,6 @@ import express from 'express' import markdownImport from 'markdown-it' import { readFileSync } from 'fs' import { getMetaFromReq } from '../server/utils.js' -import app from '../index.js' const router = express.Router() const md = markdownImport({ typographer: true }) @@ -70,15 +69,8 @@ router.get('/.well-known/webfinger', (req, res) => { router.get('/.well-known/keyoxide/version', async (req, res) => { // TODO Support responding with JSON object when requested - - let versionDetails = app.get('git_branch') - ? `+${app.get('git_branch')}` - : '' - versionDetails += (app.get('git_branch') && app.get('git_hash')) - ? `.${app.get('git_hash').substring(0, 10)}` - : '' - - return res.status(200).contentType('text/plain').send(`${app.get('keyoxide_name')}/${app.get('keyoxide_version')}${versionDetails}`) + const meta = getMetaFromReq(req) + return res.status(200).contentType('text/plain').send(meta.keyoxide.semver) }) router.get('/users/keyoxide', (req, res) => { diff --git a/src/server/utils.js b/src/server/utils.js index a4583ac..852d989 100644 --- a/src/server/utils.js +++ b/src/server/utils.js @@ -82,10 +82,30 @@ export function encodeZBase32 (data) { } export function getMetaFromReq (req) { + let versionDetails = req.app.get('git_branch') + ? `+${req.app.get('git_branch')}` + : '' + versionDetails += (req.app.get('git_branch') && req.app.get('git_hash')) + ? `.${req.app.get('git_hash').substring(0, 10)}` + : '' + + const semver = `${req.app.get('keyoxide_name')}/${req.app.get('keyoxide_version')}${versionDetails}` + + const sourceUrl = req.app.get('git_hash') + ? `https://codeberg.org/keyoxide/keyoxide-web/src/commit/${req.app.get('git_hash')}` + : req.app.get('git_branch') + ? `https://codeberg.org/keyoxide/keyoxide-web/src/branch/${req.app.get('git_branch')}` + : 'https://codeberg.org/keyoxide/keyoxide-web' + return { env: req.app.get('env'), keyoxide: { - version: req.app.get('keyoxide_version') + name: req.app.get('keyoxide_name'), + version: req.app.get('keyoxide_version'), + branch: req.app.get('git_branch'), + hash: req.app.get('git_hash'), + semver, + sourceUrl } } }