Load API_BASE_URL from backend

- Remove api_base_url constant
This commit is contained in:
Hauke Tönjes 2021-06-28 21:58:07 +02:00
parent bb23afc000
commit e4537e250d
No known key found for this signature in database
GPG Key ID: 0BF2BC96C9FAAE9E
3 changed files with 61 additions and 55 deletions

4
pages/api/config.js Normal file
View File

@ -0,0 +1,4 @@
export default function handler(req, res) {
// Return the API_BASE_URL. This Endpoint allows us to access the env Variable in client javascript
res.status(200).json({ apiBaseUrl: process.env.API_BASE_URL })
}

View File

@ -1,5 +1,3 @@
exports.API_BASE_URL = 'https://api.covidpass.marvinsextro.de/'
exports.VALUE_SET_BASE_URL = 'https://raw.githubusercontent.com/ehn-dcc-development/ehn-dcc-valuesets/main/' exports.VALUE_SET_BASE_URL = 'https://raw.githubusercontent.com/ehn-dcc-development/ehn-dcc-valuesets/main/'
exports.VALUE_TYPES = { exports.VALUE_TYPES = {
medicalProducts: 'vaccine-medicinal-product.json', medicalProducts: 'vaccine-medicinal-product.json',

View File

@ -14,24 +14,24 @@ exports.createPass = async function(data) {
sha.update(buffer); sha.update(buffer);
return sha.digest('hex'); return sha.digest('hex');
} }
async function signPassWithRemote(pass, payload) { async function signPassWithRemote(pass, payload) {
// From pass-js // From pass-js
// https://github.com/walletpass/pass-js/blob/2b6475749582ca3ea742a91466303cb0eb01a13a/src/pass.ts // https://github.com/walletpass/pass-js/blob/2b6475749582ca3ea742a91466303cb0eb01a13a/src/pass.ts
// Creating new Zip file // Creating new Zip file
const zip = [] const zip = []
// Adding required files // Adding required files
// Create pass.json // Create pass.json
zip.push({ path: 'pass.json', data: Buffer.from(JSON.stringify(pass)) }) zip.push({ path: 'pass.json', data: Buffer.from(JSON.stringify(pass)) })
const passHash = getBufferHash(Buffer.from(JSON.stringify(pass))) const passHash = getBufferHash(Buffer.from(JSON.stringify(pass)))
zip.push({ path: 'icon.png', data: payload.img1x }) zip.push({ path: 'icon.png', data: payload.img1x })
zip.push({ path: 'icon@2x.png', data: payload.img2x }) zip.push({ path: 'icon@2x.png', data: payload.img2x })
zip.push({ path: 'logo.png', data: payload.img1x }) zip.push({ path: 'logo.png', data: payload.img1x })
zip.push({ path: 'logo@2x.png', data: payload.img2x }) zip.push({ path: 'logo@2x.png', data: payload.img2x })
// adding manifest // adding manifest
// Construct manifest here // Construct manifest here
const manifestJson = JSON.stringify( const manifestJson = JSON.stringify(
@ -44,8 +44,12 @@ exports.createPass = async function(data) {
), ),
); );
zip.push({ path: 'manifest.json', data: manifestJson }); zip.push({ path: 'manifest.json', data: manifestJson });
const response = await fetch(`${constants.API_BASE_URL}/sign`, { // Load API_BASE_URL form nextjs backend
const configResponse = await fetch('/api/config')
const apiBaseUrl = (await configResponse.json()).apiBaseUrl
const response = await fetch(`${apiBaseUrl}/sign`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'application/octet-stream', 'Accept': 'application/octet-stream',
@ -55,19 +59,19 @@ exports.createPass = async function(data) {
PassJsonHash: passHash, PassJsonHash: passHash,
}) })
}) })
if (response.status !== 200) { if (response.status !== 200) {
return undefined return undefined
} }
const manifestSignature = await response.arrayBuffer() const manifestSignature = await response.arrayBuffer()
zip.push({ path: 'signature', data: Buffer.from(manifestSignature) }); zip.push({ path: 'signature', data: Buffer.from(manifestSignature) });
// finished! // finished!
return toBuffer(zip); return toBuffer(zip);
} }
let valueSets let valueSets
try { try {
@ -107,69 +111,69 @@ exports.createPass = async function(data) {
barcode: qrCode, barcode: qrCode,
generic: { generic: {
headerFields: [ headerFields: [
{ {
key: "type", key: "type",
label: "Certificate Type", label: "Certificate Type",
value: payload.certificateType value: payload.certificateType
} }
], ],
primaryFields: [ primaryFields: [
{ {
key: "name", key: "name",
label: "Name", label: "Name",
value: payload.name value: payload.name
} }
], ],
secondaryFields: [ secondaryFields: [
{ {
key: "dose", key: "dose",
label: "Dose", label: "Dose",
value: payload.dose value: payload.dose
}, },
{ {
key: "dov", key: "dov",
label: "Date of Vaccination", label: "Date of Vaccination",
value: payload.dateOfVaccination, value: payload.dateOfVaccination,
textAlignment: "PKTextAlignmentRight" textAlignment: "PKTextAlignmentRight"
} }
], ],
auxiliaryFields: [ auxiliaryFields: [
{ {
key: "vaccine", key: "vaccine",
label: "Vaccine", label: "Vaccine",
value: payload.vaccineName value: payload.vaccineName
}, },
{ {
key: "dob", key: "dob",
label: "Date of Birth", value: label: "Date of Birth", value:
payload.dateOfBirth, payload.dateOfBirth,
textAlignment: "PKTextAlignmentRight" textAlignment: "PKTextAlignmentRight"
} }
], ],
backFields: [ backFields: [
{ {
key: "uvci", key: "uvci",
label: "Unique Certificate Identifier (UVCI)", label: "Unique Certificate Identifier (UVCI)",
value: payload.uvci value: payload.uvci
}, },
{ {
key: "issuer", key: "issuer",
label: "Certificate Issuer", label: "Certificate Issuer",
value: payload.certificateIssuer value: payload.certificateIssuer
}, },
{ {
key: "country", key: "country",
label: "Country of Vaccination", label: "Country of Vaccination",
value: payload.countryOfVaccination value: payload.countryOfVaccination
}, },
{ {
key: "manufacturer", key: "manufacturer",
label: "Manufacturer", label: "Manufacturer",
value: payload.manufacturer value: payload.manufacturer
}, },
{ {
key: "disclaimer", key: "disclaimer",
label: "Disclaimer", label: "Disclaimer",
value: "This certificate is only valid in combination with the ID card of the certificate holder and expires one year + 14 days after the last dose. The validity of this certificate was not checked by CovidPass." value: "This certificate is only valid in combination with the ID card of the certificate holder and expires one year + 14 days after the last dose. The validity of this certificate was not checked by CovidPass."
} }
] ]