fix: simplify version API endpoint

This commit is contained in:
Yarmo Mackenbach 2024-01-27 21:44:11 +01:00
parent e55a0b2b77
commit de2a938ccc
No known key found for this signature in database
GPG key ID: C248C28D432560ED
4 changed files with 7 additions and 12 deletions

View file

@ -29,7 +29,6 @@
},
"devDependencies": {
"@biomejs/biome": "1.2.2",
"@richex/git-last-commit": "^2.1.1",
"@vercel/ncc": "^0.34.0",
"chai": "^4.3.6",
"copy-webpack-plugin": "^11.0.0",

View file

@ -37,8 +37,11 @@ const router = express.Router()
router.get('/version', async (req, res) => {
// TODO Support responding with JSON object when requested
const versionDetails = (app.get('git_branch') && app.get('git_hash'))
? `+${app.get('git_branch')}.${app.get('git_hash').substring(0, 10)}`
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}`)

View file

@ -27,7 +27,6 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/
import git from '@richex/git-last-commit'
import express from 'express'
import * as httpContext from 'express-http-context2'
import { nanoid } from 'nanoid'
@ -46,7 +45,6 @@ dotenv.config()
const app = express()
const packageData = JSON.parse(readFileSync('./package.json'))
const commit = await git.getLastCommitAsync()
app.set('env', process.env.NODE_ENV || 'production')
app.engine('pug', pug.__express).set('view engine', 'pug')
@ -55,8 +53,8 @@ app.set('domain', process.env.DOMAIN)
app.set('scheme', process.env.SCHEME || 'https')
app.set('keyoxide_name', 'keyoxide-web')
app.set('keyoxide_version', packageData.version)
app.set('git_branch', commit.branch ?? process.env.CI_COMMIT_BRANCH ?? process.env.COMMIT_BRANCH)
app.set('git_hash', commit.hash ?? process.env.CI_COMMIT_SHA ?? process.env.COMMIT_SHA)
app.set('git_branch', process.env.CI_COMMIT_BRANCH ?? process.env.COMMIT_BRANCH)
app.set('git_hash', process.env.CI_COMMIT_SHA ?? process.env.COMMIT_SHA)
app.set('onion_url', process.env.ONION_URL)
// Middlewares

View file

@ -488,11 +488,6 @@
resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.24.tgz#58601079e11784d20f82d0585865bb42305c4df3"
integrity sha512-2LuNTFBIO0m7kKIQvvPHN6UE63VjpmL9rnEEaOOaiSPbZK+zUOYIzBAWcED+3XYzhYsd/0mD57VdxAEqqV52CQ==
"@richex/git-last-commit@^2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@richex/git-last-commit/-/git-last-commit-2.1.1.tgz#b6527ae4223af8143f13e39d8f0cdaeaed7f9ba6"
integrity sha512-rNa0hCMyKTJ+qPwyN54FlwTUhDBNNghiQWt0ES27g11iYzyzpLcFBGLKYhDaEEEUPZ7aawXOCEYAwCg5JZ1FAQ==
"@sindresorhus/is@^4.0.0":
version "4.6.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.6.0.tgz#3c7c9c46e678feefe7a2e5bb609d3dbd665ffb3f"