Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC for bruk av Gotenberg til å generere PDF av søknad #1380

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .nais/fyllut/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ spec:
value: {{skjemabygging-proxy-url}}
- name: SKJEMABYGGING_PROXY_CLIENT_ID
value: {{skjemabygging-proxy-client-id}}
- name: GOTENBERG_URL
value: {{gotenberg-url}}
- name: SEND_INN_TOKEN_X_CLIENT_ID
value: {{send-inn-token-x-client-id}}
- name: SEND_INN_HOST
Expand Down
3 changes: 3 additions & 0 deletions .nais/fyllut/dev-delingslenke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ foersteside-url: https://www.nav.no/soknader/api/forsteside
dekorator-url: https://www.nav.no/dekoratoren?simple=true
skjemabygging-proxy-client-id: 95170319-b4d7-4190-8271-118ed19bafbf
skjemabygging-proxy-url: https://skjemabygging-proxy.dev-fss-pub.nais.io
gotenberg-url: http://upload-convert-to-pdf.fyllut-sendinn
send-inn-token-x-client-id: dev-gcp:team-soknad:innsending-api
send-inn-host: http://innsending-api.team-soknad
forms-api-url: https://forms-api.nav.no
Expand Down Expand Up @@ -46,6 +47,8 @@ accessPolicy:
- application: nav-dekoratoren
namespace: personbruker
cluster: dev-gcp
- application: upload-convert-to-pdf
namespace: fyllut-sendinn
nils-arne marked this conversation as resolved.
Show resolved Hide resolved
external:
- host: skjemabygging-proxy.dev-fss-pub.nais.io
- host: formio-api.intern.dev.nav.no
Expand Down
3 changes: 3 additions & 0 deletions .nais/fyllut/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ foersteside-url: https://www.nav.no/soknader/api/forsteside
dekorator-url: https://www.nav.no/dekoratoren?simple=true
skjemabygging-proxy-client-id: 95170319-b4d7-4190-8271-118ed19bafbf
skjemabygging-proxy-url: https://skjemabygging-proxy.dev-fss-pub.nais.io
gotenberg-url: http://upload-convert-to-pdf.fyllut-sendinn
send-inn-token-x-client-id: dev-gcp:team-soknad:innsending-api
send-inn-host: http://innsending-api.team-soknad
kodeverk:
Expand Down Expand Up @@ -40,6 +41,8 @@ accessPolicy:
- application: forms-api
namespace: fyllut-sendinn
cluster: dev-gcp
- application: upload-convert-to-pdf
namespace: fyllut-sendinn
external:
- host: skjemabygging-proxy.dev-fss-pub.nais.io
- host: formio-api.intern.dev.nav.no
Expand Down
3 changes: 3 additions & 0 deletions .nais/fyllut/preprod-alt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ foersteside-url: https://www.nav.no/soknader/api/forsteside
dekorator-url: https://www.nav.no/dekoratoren?simple=true
skjemabygging-proxy-client-id: 95170319-b4d7-4190-8271-118ed19bafbf
skjemabygging-proxy-url: https://skjemabygging-proxy.dev-fss-pub.nais.io
gotenberg-url: http://upload-convert-to-pdf.fyllut-sendinn
nils-arne marked this conversation as resolved.
Show resolved Hide resolved
send-inn-token-x-client-id: dev-gcp:team-soknad:innsending-api
send-inn-host: http://innsending-api.team-soknad
kodeverk:
Expand Down Expand Up @@ -47,6 +48,8 @@ accessPolicy:
- application: forms-api
namespace: fyllut-sendinn
cluster: dev-gcp
- application: upload-convert-to-pdf
namespace: fyllut-sendinn
external:
- host: skjemabygging-proxy.dev-fss-pub.nais.io
- host: formio-api.intern.dev.nav.no
Expand Down
3 changes: 3 additions & 0 deletions .nais/fyllut/preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ foersteside-url: https://www.nav.no/soknader/api/forsteside
dekorator-url: https://www.nav.no/dekoratoren?simple=true
skjemabygging-proxy-client-id: 95170319-b4d7-4190-8271-118ed19bafbf
skjemabygging-proxy-url: https://skjemabygging-proxy.dev-fss-pub.nais.io
gotenberg-url: http://upload-convert-to-pdf.fyllut-sendinn
send-inn-token-x-client-id: dev-gcp:team-soknad:innsending-api
send-inn-host: http://innsending-api.team-soknad
kodeverk:
Expand Down Expand Up @@ -48,6 +49,8 @@ accessPolicy:
- application: forms-api
namespace: fyllut-sendinn
cluster: dev-gcp
- application: upload-convert-to-pdf
namespace: fyllut-sendinn
external:
- host: skjemabygging-proxy.dev-fss-pub.nais.io
- host: formio-api.intern.dev.nav.no
Expand Down
3 changes: 3 additions & 0 deletions .nais/fyllut/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ foersteside-url: https://www.nav.no/soknader/api/forsteside
dekorator-url: https://www.nav.no/dekoratoren?simple=true
skjemabygging-proxy-client-id: 031863f2-9881-44af-ace5-6b5ab52afeb1
skjemabygging-proxy-url: https://skjemabygging-proxy.prod-fss-pub.nais.io
gotenberg-url: http://upload-convert-to-pdf.fyllut-sendinn
send-inn-token-x-client-id: prod-gcp:team-soknad:innsending-api
send-inn-host: http://innsending-api.team-soknad
kodeverk:
Expand Down Expand Up @@ -45,6 +46,8 @@ accessPolicy:
- application: forms-api
namespace: fyllut-sendinn
cluster: prod-gcp
- application: upload-convert-to-pdf
namespace: fyllut-sendinn
external:
- host: skjemabygging-proxy.prod-fss-pub.nais.io
- host: formio-api.intern.nav.no
2 changes: 1 addition & 1 deletion mocks/mocks/routes/skjemabygging-proxy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = [
{
id: 'post-exstream-pdf',
url: '/skjemabygging-proxy/exstream',
url: '/skjemabygging-proxy/gotenberg',
nils-arne marked this conversation as resolved.
Show resolved Hide resolved
method: 'POST',
variants: [
{
Expand Down
3 changes: 3 additions & 0 deletions packages/fyllut-backend/icons/nav-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/fyllut-backend/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const localDevelopmentConfig: DefaultConfig = {
decoratorUrl: 'https://www.nav.no/dekoratoren?simple=true',
skjemabyggingProxyUrl: process.env.SKJEMABYGGING_PROXY_URL || 'https://skjemabygging-proxy.dev-fss-pub.nais.io',
skjemabyggingProxyClientId: '95170319-b4d7-4190-8271-118ed19bafbf',
gotenbergUrl: process.env.GOTENBERG_URL || 'https://upload-convert-to-pdf.fyllut-sendinn',
nils-arne marked this conversation as resolved.
Show resolved Hide resolved
azureOpenidTokenEndpoint:
process.env.AZURE_OPENID_CONFIG_TOKEN_ENDPOINT ||
'https://login.microsoftonline.com/966ac572-f5b7-4bbe-aa88-c76419c0f851/oauth2/v2.0/token',
Expand Down Expand Up @@ -125,6 +126,7 @@ const defaultConfig: DefaultConfig = {
decoratorUrl: process.env.DECORATOR_URL!,
skjemabyggingProxyUrl: process.env.SKJEMABYGGING_PROXY_URL!,
skjemabyggingProxyClientId: process.env.SKJEMABYGGING_PROXY_CLIENT_ID!,
gotenbergUrl: process.env.GOTENBERG_URL!,
azureOpenidTokenEndpoint: process.env.AZURE_OPENID_CONFIG_TOKEN_ENDPOINT!,
clientId: process.env.AZURE_APP_CLIENT_ID!,
skjemaDir: process.env.SKJEMA_DIR!,
Expand Down
1 change: 1 addition & 0 deletions packages/fyllut-backend/src/config/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type DefaultConfig = {
decoratorUrl: string;
skjemabyggingProxyUrl: string;
skjemabyggingProxyClientId: string;
gotenbergUrl: string;
azureOpenidTokenEndpoint: string;
clientId: string;
skjemaDir?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Submission,
} from '@navikt/skjemadigitalisering-shared-domain';
import { NextFunction, Request, Response } from 'express';
import { base64Decode } from '../../utils/base64';
import { htmlResponseError } from '../../utils/errorHandling';
import { logErrorWithStacktrace } from '../../utils/errors';
import { createPdf } from './helpers/pdfService';
Expand All @@ -28,7 +27,7 @@ const parseBody = (
return { form, submission, submissionMethod, translations, language };
};

const exstream = {
const gotenberg = {
post: async (req: Request, res: Response, next: NextFunction) => {
try {
const { form, submission, submissionMethod, translations, language } = parseBody(req);
Expand All @@ -42,8 +41,9 @@ const exstream = {
translations,
languageCode,
);
res.contentType(pdf.contentType);
res.send(base64Decode(pdf.data));

res.setHeader('Content-Type', 'application/pdf');
res.status(200).send(Buffer.from(new Uint8Array(pdf)));
} catch (e) {
logErrorWithStacktrace(e as Error);
const createPdfError = htmlResponseError('Generering av PDF feilet');
Expand All @@ -52,4 +52,4 @@ const exstream = {
},
};

export default exstream;
export default gotenberg;
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ p {margin: 0}
.alt {margin-bottom: 5px; font-family: "Courier New", sans-serif; font-style: italic;}
.innrykk {margin: 0px 0px 10px 20px;}
.underskrift {margin-bottom: 30px;}
.navlogored {height: 16px;float: left;margin: 4px auto 2px auto;}
</style>`;

const body = (formSummaryObject: SummaryPanel[], confirmation?: string, signatures?: string) => `
<body>
${navlogo}
${formSummaryObject.map(section).join('')}
${confirmation || ''}
${signatures || ''}
</body>`;

const navlogo: string = `<img xmlns="http://www.w3.org/2000/svg " src="Nav-logo.svg" alt="NAV logo" class="navlogored" x="0" height="16px"/>`;

const section = (formSection: SummaryPanel) => `
<h2>${formSection.label}</h2>
${sectionContent(formSection.components, 1)}`;
Expand Down
Loading
Loading