Files
drop/server/plugins/ca.ts
DecDuck 435551c207 object storage + full permission system + testing
Object storage now works fully, with the permission system. It still
needs additional external endpoints for updating and deleting objects
from the API, but it is otherwise complete. Further tasks include
writing an S3 adapter.
2024-10-09 14:43:06 +11:00

28 lines
782 B
TypeScript

import { CertificateAuthority } from "../internal/clients/ca";
import fs from "fs";
import { fsCertificateStore } from "../internal/clients/store";
let ca: CertificateAuthority | undefined;
export const useGlobalCertificateAuthority = () => {
if (!ca) throw new Error("CA not initialised");
return ca;
};
export default defineNitroPlugin(async (nitro) => {
const basePath = process.env.CLIENT_CERTIFICATES ?? "./certs";
fs.mkdirSync(basePath, { recursive: true });
const store = fsCertificateStore(basePath);
ca = await CertificateAuthority.new(store);
nitro.hooks.hook("request", (h3) => {
if (!ca)
throw createError({
statusCode: 500,
statusMessage: "Certificate authority not initialised",
});
h3.context.ca = ca;
});
});