Rammstein
trpc openapi api memory problem
/pages/openapi.tsx
js
/pages/api
pages/api/openapi/[...trpc].ts
js
import type { NextPage } from 'next';
import dynamic from 'next/dynamic';
import 'swagger-ui-react/swagger-ui.css';
const SwaggerUI = dynamic(() => {
return import("swagger-ui-react");
}, { ssr: false });
const OpenAPIPage: NextPage = () => {
// Serve Swagger UI with our OpenAPI schema
return <SwaggerUI url="/api/openapi.json" />;
};
export default OpenAPIPage;
import type { NextPage } from 'next';
import dynamic from 'next/dynamic';
import 'swagger-ui-react/swagger-ui.css';
const SwaggerUI = dynamic(() => {
return import("swagger-ui-react");
}, { ssr: false });
const OpenAPIPage: NextPage = () => {
// Serve Swagger UI with our OpenAPI schema
return <SwaggerUI url="/api/openapi.json" />;
};
export default OpenAPIPage;
import { NextApiRequest, NextApiResponse } from 'next';
import { openApiDocument } from '../../server/configs/openapi.config';
// Respond with our OpenAPI schema
const handler = (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).send(openApiDocument);
};
export default handler;
import { NextApiRequest, NextApiResponse } from 'next';
import { openApiDocument } from '../../server/configs/openapi.config';
// Respond with our OpenAPI schema
const handler = (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).send(openApiDocument);
};
export default handler;
import { NextApiRequest, NextApiResponse } from 'next';
import { createOpenApiNextHandler } from 'trpc-openapi';
import { appRouter} from '../../../server/routers/_app';
import {createContext} from '../../../server/context';
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
// Handle incoming OpenAPI requests
return createOpenApiNextHandler({
router: appRouter,
createContext,
})(req, res);
};
export default handler;
import { NextApiRequest, NextApiResponse } from 'next';
import { createOpenApiNextHandler } from 'trpc-openapi';
import { appRouter} from '../../../server/routers/_app';
import {createContext} from '../../../server/context';
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
// Handle incoming OpenAPI requests
return createOpenApiNextHandler({
router: appRouter,
createContext,
})(req, res);
};
export default handler;
6 replies
trpc openapi api memory problem
Code:
server/routers/_app.ts
import {router} from '../init';
import {userRouter} from "./user";
import {cloudmateRouter} from "./cloudmate";
import {workspaceRouter} from "./workspace";
import {channelRouter} from "./channel";
import {projectRouter} from "./project";
import {SMSRouter} from "./sms";
import {customFieldRouter} from "./customField";
import {EmailRouter} from "./email";
import {testRouter} from "./test";
import {microsoftRouter} from "./microsoft";
import {googleRouter} from "./google";
import {AsanaWebhookRouter} from "./asanaWebhook";
import {draftRouter} from "./draft";
import {taskRouter} from "./task";
import {organizationRouter} from "./organization";
import {commandRouter} from "./command";
import {eventFilterRouter} from "./eventFilter";
import {workerRouter} from "./worker";
import {exceptionRouter} from "./exception";
export const appRouter = router({
asanaWebhook:AsanaWebhookRouter,
channel: channelRouter,
cloudmate: cloudmateRouter,
command:commandRouter,
customField: customFieldRouter,
draft: draftRouter,
email: EmailRouter,
eventFilter:eventFilterRouter,
exception:exceptionRouter,
google: googleRouter,
microsoft: microsoftRouter,
organization:organizationRouter,
project: projectRouter,
sms: SMSRouter,
task: taskRouter,
test: testRouter,
user: userRouter,
worker:workerRouter,
workspace: workspaceRouter,
});
export type AppRouter = typeof appRouter;
server/routers/_app.ts
import {router} from '../init';
import {userRouter} from "./user";
import {cloudmateRouter} from "./cloudmate";
import {workspaceRouter} from "./workspace";
import {channelRouter} from "./channel";
import {projectRouter} from "./project";
import {SMSRouter} from "./sms";
import {customFieldRouter} from "./customField";
import {EmailRouter} from "./email";
import {testRouter} from "./test";
import {microsoftRouter} from "./microsoft";
import {googleRouter} from "./google";
import {AsanaWebhookRouter} from "./asanaWebhook";
import {draftRouter} from "./draft";
import {taskRouter} from "./task";
import {organizationRouter} from "./organization";
import {commandRouter} from "./command";
import {eventFilterRouter} from "./eventFilter";
import {workerRouter} from "./worker";
import {exceptionRouter} from "./exception";
export const appRouter = router({
asanaWebhook:AsanaWebhookRouter,
channel: channelRouter,
cloudmate: cloudmateRouter,
command:commandRouter,
customField: customFieldRouter,
draft: draftRouter,
email: EmailRouter,
eventFilter:eventFilterRouter,
exception:exceptionRouter,
google: googleRouter,
microsoft: microsoftRouter,
organization:organizationRouter,
project: projectRouter,
sms: SMSRouter,
task: taskRouter,
test: testRouter,
user: userRouter,
worker:workerRouter,
workspace: workspaceRouter,
});
export type AppRouter = typeof appRouter;
6 replies
trpc openapi api memory problem
Provide environment Information System:
Cloud service provider: Render
OS: 22.04.1-Ubuntu
CPU: AMD EPYC 7R13 Processor
Memory: 2.00 GB
Binaries:
Node: 18.12.1
Packages:
@trpc/client: 10.5.0,
@trpc/next:10.5.0,
@trpc/react-query: 10.5.0,
@trpc/server:10.5.0,
next: 12.1.6,
react: "18.1.0",
swagger-ui-react:^4.15.5,
trpc-openapi:^1.0.0,
6 replies
tRPC sockets with react
trpc.ts
this is just a test page i am using
/pages/test/trpc-test.tsx
import { Context } from "./context";
import {initTRPC, TRPCError} from '@trpc/server';
import superjson from 'superjson';
import { OpenApiMeta } from 'trpc-openapi';
const t = initTRPC.context<Context>().meta<OpenApiMeta>().create({
transformer: superjson,
errorFormatter({ shape }) {
return shape;
},
});
export const router = t.router;
export const publicProcedure = t.procedure;
const isAuthed = t.middleware(({ next, ctx }) => {
if (!ctx.user) {
throw new TRPCError({message:"UNAUTHORIZED",code: 'UNAUTHORIZED' });
}
return next({
ctx: {
user: ctx.user,
},
});
});
export const hasCloudmate = t.middleware(({next,ctx})=>{
if (!ctx.cloudmateUserObject || !ctx.cloudmateAsanaObject) {
throw new TRPCError({message:"CLOUDMATE NOT COMPLETELY SETUP",code: "PRECONDITION_FAILED" });
}
if(!ctx.ownerUserObject || !ctx.ownerAsanaObject){
throw new TRPCError({message:"CREATOR USER NOT COMPLETELY SETUP",code: "PRECONDITION_FAILED" });
}
return next();
});
// you can reuse this for any procedure
export const protectedProcedure = t.procedure.use(isAuthed);
export const middleware = t.middleware;
export const mergeRouters = t.mergeRouters;
import { Context } from "./context";
import {initTRPC, TRPCError} from '@trpc/server';
import superjson from 'superjson';
import { OpenApiMeta } from 'trpc-openapi';
const t = initTRPC.context<Context>().meta<OpenApiMeta>().create({
transformer: superjson,
errorFormatter({ shape }) {
return shape;
},
});
export const router = t.router;
export const publicProcedure = t.procedure;
const isAuthed = t.middleware(({ next, ctx }) => {
if (!ctx.user) {
throw new TRPCError({message:"UNAUTHORIZED",code: 'UNAUTHORIZED' });
}
return next({
ctx: {
user: ctx.user,
},
});
});
export const hasCloudmate = t.middleware(({next,ctx})=>{
if (!ctx.cloudmateUserObject || !ctx.cloudmateAsanaObject) {
throw new TRPCError({message:"CLOUDMATE NOT COMPLETELY SETUP",code: "PRECONDITION_FAILED" });
}
if(!ctx.ownerUserObject || !ctx.ownerAsanaObject){
throw new TRPCError({message:"CREATOR USER NOT COMPLETELY SETUP",code: "PRECONDITION_FAILED" });
}
return next();
});
// you can reuse this for any procedure
export const protectedProcedure = t.procedure.use(isAuthed);
export const middleware = t.middleware;
export const mergeRouters = t.mergeRouters;
import { trpc } from "../../utils/trpc";
import { useEffect, useState } from "react";
const TestPage = () => {
const [userData, setUserData] = useState<any>();
const [orgData, setOrgData] = useState<any>();
const { data: users } = trpc.user.listUsers.useQuery();
const { data: organizations } = trpc.workspace.getWorkspaces.useQuery({});
console.log("Orgs: ", organizations);
useEffect(() => {
setUserData(users);
setOrgData(organizations);
console.log("user state", userData);
}, [users, userData, organizations, orgData]);
if (!users) return;
return (
<div>
</div>
);
};
export default TestPage;
import { trpc } from "../../utils/trpc";
import { useEffect, useState } from "react";
const TestPage = () => {
const [userData, setUserData] = useState<any>();
const [orgData, setOrgData] = useState<any>();
const { data: users } = trpc.user.listUsers.useQuery();
const { data: organizations } = trpc.workspace.getWorkspaces.useQuery({});
console.log("Orgs: ", organizations);
useEffect(() => {
setUserData(users);
setOrgData(organizations);
console.log("user state", userData);
}, [users, userData, organizations, orgData]);
if (!users) return;
return (
<div>
</div>
);
};
export default TestPage;
12 replies
tRPC sockets with react
Hi I am facing similar problem for a long time now. Can you guys please help me out?
Following are the files
utils/trpc.ts
__app.tsx
trpc/[trpc].ts
import { httpBatchLink, loggerLink } from '@trpc/client';
import { createTRPCNext } from '@trpc/next';
import superjson from 'superjson';
import type { AppRouter } from "../server/routers/_app";
import SuperJSON from "superjson";
function getBaseUrl() {
if (typeof window !== 'undefined') {
return '';
}
if (process.env.VERCEL_URL) {
return `https://${process.env.VERCEL_URL}`;
}
if (process.env.RENDER_INTERNAL_HOSTNAME) {
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
}
return `http://127.0.0.1:${process.env.PORT ?? 3000}`;
}
export const trpc = createTRPCNext<AppRouter>({
config({ ctx }) {
return {
transformer: superjson,
links: [
httpBatchLink({
url: getBaseUrl() + '/api/trpc',
}),
],
};
},
ssr: false,
});
import { httpBatchLink, loggerLink } from '@trpc/client';
import { createTRPCNext } from '@trpc/next';
import superjson from 'superjson';
import type { AppRouter } from "../server/routers/_app";
import SuperJSON from "superjson";
function getBaseUrl() {
if (typeof window !== 'undefined') {
return '';
}
if (process.env.VERCEL_URL) {
return `https://${process.env.VERCEL_URL}`;
}
if (process.env.RENDER_INTERNAL_HOSTNAME) {
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
}
return `http://127.0.0.1:${process.env.PORT ?? 3000}`;
}
export const trpc = createTRPCNext<AppRouter>({
config({ ctx }) {
return {
transformer: superjson,
links: [
httpBatchLink({
url: getBaseUrl() + '/api/trpc',
}),
],
};
},
ssr: false,
});
import '../styles/globals.css';
import type {AppProps, AppType} from 'next/app';
import Theme from '../styles/Theme';
import { trpc } from '../utils/trpc';
const MyApp:AppType=({ Component, pageProps }: AppProps)=> {
return (
<Theme>
<Component {...pageProps} />
</Theme>
);
}
export default trpc.withTRPC(MyApp);
import '../styles/globals.css';
import type {AppProps, AppType} from 'next/app';
import Theme from '../styles/Theme';
import { trpc } from '../utils/trpc';
const MyApp:AppType=({ Component, pageProps }: AppProps)=> {
return (
<Theme>
<Component {...pageProps} />
</Theme>
);
}
export default trpc.withTRPC(MyApp);
import * as trpcNext from '@trpc/server/adapters/next';
import { createContext } from '../../../server/context';
import { appRouter } from '../../../server/routers/_app';
export default trpcNext.createNextApiHandler({
router: appRouter,
createContext,
});
import * as trpcNext from '@trpc/server/adapters/next';
import { createContext } from '../../../server/context';
import { appRouter } from '../../../server/routers/_app';
export default trpcNext.createNextApiHandler({
router: appRouter,
createContext,
});
12 replies