mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-16 07:25:38 +00:00
Completely refactored examples to run only once and have multiple endpoints
This commit is contained in:
41
examples/self-hosted/src/shared.ts
Normal file
41
examples/self-hosted/src/shared.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
|
||||
const certificatesCache: Partial<{
|
||||
signerCert: Buffer;
|
||||
signerKey: Buffer;
|
||||
wwdr: Buffer;
|
||||
signerKeyPassphrase: string;
|
||||
}> = {};
|
||||
|
||||
export async function getCertificates(): Promise<typeof certificatesCache> {
|
||||
if (Object.keys(certificatesCache).length) {
|
||||
return certificatesCache;
|
||||
}
|
||||
|
||||
const [signerCert, signerKey, wwdr, signerKeyPassphrase] =
|
||||
await Promise.all([
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, "../../../certificates/signerCert.pem"),
|
||||
"utf-8",
|
||||
),
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, "../../../certificates/signerKey.pem"),
|
||||
"utf-8",
|
||||
),
|
||||
fs.readFile(
|
||||
path.resolve(__dirname, "../../../certificates/WWDR.pem"),
|
||||
"utf-8",
|
||||
),
|
||||
Promise.resolve("123456"),
|
||||
]);
|
||||
|
||||
Object.assign(certificatesCache, {
|
||||
signerCert,
|
||||
signerKey,
|
||||
wwdr,
|
||||
signerKeyPassphrase,
|
||||
});
|
||||
|
||||
return certificatesCache;
|
||||
}
|
||||
Reference in New Issue
Block a user