Skip to content

Commit

Permalink
Endpoint for certificate fonts & configuration (#782)
Browse files Browse the repository at this point in the history
* Serve fonts & certificate configuration

* Use noto-sans in certificate config
  • Loading branch information
Zangetsu101 authored Nov 8, 2023
1 parent aadd271 commit e049853
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 2 deletions.
2 changes: 1 addition & 1 deletion infrastructure/docker-compose.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ services:
replicas: 1
environment:
- APN_SERVICE_URL=http://apm-server:8200
- COUNTRY_LOGO_URL=https://countryconfig.{{hostname}}/content/country-logo
- COUNTRY_CONFIG_URL=https://countryconfig.{{hostname}}
- LOGIN_URL=https://login.{{hostname}}
- CLIENT_APP_URL=https://register.{{hostname}}
- DOMAIN={{hostname}}
Expand Down
36 changes: 36 additions & 0 deletions src/api/certificate-configuration/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import { COUNTRY_CONFIG_URL } from '@countryconfig/constants'

type FontFamilyTypes = {
normal: string
bold: string
italics: string
bolditalics: string
}

type Configuration = Partial<{
fonts: Record<string, FontFamilyTypes>
}>

export function certificateConfigurationHandler(): Configuration {
return {
fonts: {
['Noto Sans']: {
normal: `${COUNTRY_CONFIG_URL}/fonts/NotoSans-Regular.ttf`,
bold: `${COUNTRY_CONFIG_URL}/fonts/NotoSans-SemiBold.ttf`,
italics: `${COUNTRY_CONFIG_URL}/fonts/NotoSans-Regular.ttf`,
bolditalics: `${COUNTRY_CONFIG_URL}/fonts/NotoSans-Regular.ttf`
}
}
}
}
Binary file added src/api/fonts/NotoSans-Regular.ttf
Binary file not shown.
Binary file added src/api/fonts/NotoSans-SemiBold.ttf
Binary file not shown.
17 changes: 17 additions & 0 deletions src/api/fonts/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import { Request, ResponseToolkit } from '@hapi/hapi'
import { join } from 'path'

export function fontsHandler(request: Request, h: ResponseToolkit) {
return h.file(join(__dirname, request.params.filename))
}
4 changes: 3 additions & 1 deletion src/api/notification/constant.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { COUNTRY_CONFIG_URL } from '@countryconfig/constants'

/* SMTP (Email) */
export const SMTP_HOST = process.env.SMTP_HOST
export const SMTP_PORT = process.env.SMTP_PORT
Expand All @@ -19,7 +21,7 @@ export const INFOBIP_SENDER_ID = process.env.INFOBIP_SENDER_ID

export const EMAIL_API_KEY = process.env.EMAIL_API_KEY

export const COUNTRY_LOGO_URL = process.env.COUNTRY_LOGO_URL as string
export const COUNTRY_LOGO_URL = `${COUNTRY_CONFIG_URL}/content/country-logo`

export const LOGIN_URL = process.env.LOGIN_URL as string

Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const ORG_URL = 'http://opencrvs.org'
export const COUNTRY_CONFIG_HOST = process.env.COUNTRY_CONFIG_HOST || '0.0.0.0'
export const COUNTRY_CONFIG_PORT = process.env.COUNTRY_CONFIG_PORT || 3040
export const AUTH_URL = process.env.AUTH_URL || 'http://localhost:4040'
export const COUNTRY_CONFIG_URL =
process.env.COUNTRY_CONFIG_URL || 'http://localhost:3040'
export const APPLICATION_CONFIG_URL =
process.env.APPLICATION_CONFIG_URL || 'http://localhost:2021/'
export const SENTRY_DSN = process.env.SENTRY_DSN
Expand Down
29 changes: 29 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import { conditionalsHandler } from './form/common/custom-validation-conditional
import { COUNTRY_WIDE_CRUDE_DEATH_RATE } from './api/application/application-config-default'
import { handlebarsHandler } from './form/common/certificate/handlebars/handler'
import { trackingIDHandler } from './api/tracking-id/handler'
import { fontsHandler } from './api/fonts/handler'
import { certificateConfigurationHandler } from './api/certificate-configuration/handler'

export interface ITokenPayload {
sub: string
Expand Down Expand Up @@ -234,6 +236,11 @@ export async function createServer() {
server.auth.default('jwt')

// add ping route by default for health check
server.route({
method: 'GET',
path: '/certificates/{event}.svg',
handler: certificateHandler
})

server.route({
method: 'GET',
Expand All @@ -251,6 +258,28 @@ export async function createServer() {
}
})

server.route({
method: 'GET',
path: '/fonts/{filename}',
handler: fontsHandler,
options: {
auth: false,
tags: ['api'],
description: 'Serves available fonts'
}
})

server.route({
method: 'GET',
path: '/certificate-configuration',
handler: certificateConfigurationHandler,
options: {
auth: false,
tags: ['api'],
description: 'Serves certificate configurations'
}
})

server.route({
method: 'GET',
path: '/client-config.js',
Expand Down

0 comments on commit e049853

Please sign in to comment.