All files / api/misc misc.ts

100% Statements 42/42
87.5% Branches 7/8
100% Functions 2/2
100% Lines 42/42

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 431x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 154x 154x 154x 154x 154x 1x 2x 2x 2x 2x 2x  
import Koa from 'koa';
 
import { getVersionNumFromPackageJson } from '@helpers/fileHelper';
import { anyObject } from '@helpers/typescriptHacks';
import { getConfig } from '@services/internal/configService';
import { isRequestAuthed } from '../guard/hasAuth';
 
export const defaultEndpoint = async (
  ctx: Koa.DefaultContext,
  next: () => Promise<Koa.BaseResponse>,
) => {
  ctx.response.status = 303;
  ctx.redirect(getConfig().getNmsUdFormWebUrl());
 
  await next();
};
 
export const versionEndpoint =
  (authToken: string) => async (ctx: Koa.DefaultContext, next: () => Promise<Koa.BaseResponse>) => {
    const isAdmin = await isRequestAuthed(
      authToken,
      ctx,
      () => new Promise((res) => res(anyObject)), // fake next, because we still want to do stuff if not authed
    );
 
    let output = `DOCKER_BUILD_VERSION: ${getConfig().buildVersion() ?? '???'}\n`;
    output += `packageVersion: ${getVersionNumFromPackageJson()}\n`;
 
    if (isAdmin) {
      output += '\nAuthenticate properties:\n\n';
      for (const processKey in process.env) {
        if (Object.prototype.hasOwnProperty.call(process.env, processKey)) {
          const element = process.env[processKey];
          output += `${processKey}: ${element}\n`;
        }
      }
    }
 
    ctx.body = output;
 
    await next();
  };