mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-11 08:18:37 +01:00
new selfhosted version
This commit is contained in:
52
dashboard/server/plugins/trpc.ts
Normal file
52
dashboard/server/plugins/trpc.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
import type { AppRouter as PaymentsAppRouter } from '../../../payments/src/index';
|
||||
import type { AppRouter as EmailAppRouter } from '../../../emails/src/index';
|
||||
import { createTRPCClient, httpBatchLink, TRPCClient } from '@trpc/client';
|
||||
|
||||
|
||||
export type tRpcPaymentsType = TRPCClient<PaymentsAppRouter>;
|
||||
export type tRpcEmailsType = TRPCClient<EmailAppRouter>;
|
||||
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
|
||||
export default defineNitroPlugin(async nitroApp => {
|
||||
try {
|
||||
|
||||
if (isSelfhosted()) return;
|
||||
|
||||
const tRpcPayments = createTRPCClient<PaymentsAppRouter>({
|
||||
links: [
|
||||
httpBatchLink({
|
||||
url: config.PAYMENT_TRPC_URL,
|
||||
headers: {
|
||||
Authorization: `Bearer ${config.PAYMENT_SECRET}`
|
||||
}
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const tRpcEmails = createTRPCClient<EmailAppRouter>({
|
||||
links: [
|
||||
httpBatchLink({
|
||||
url: config.EMAIL_TRPC_URL,
|
||||
headers: {
|
||||
Authorization: `Bearer ${config.EMAIL_SECRET}`
|
||||
}
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
const app = nitroApp as any;
|
||||
|
||||
app.shared = app.shared || {};
|
||||
app.shared.tRpcPayments = tRpcPayments;
|
||||
app.shared.tRpcEmails = tRpcEmails;
|
||||
|
||||
console.log('tRpc setup complete.')
|
||||
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user