Replies: 1 comment
-
I was able to generate OpenApi spec with https://github.com/jlalmes/trpc-openapi, but I am not able to start server at the same time. src/routes/openapi/+page.server.ts import type { PageServerLoad } from './$types';
import { openApiDocument } from '$lib/server/openapi';
export const load: PageServerLoad = async (event) => {
console.log(openApiDocument);
return {openApiDocument};
}; src/lib/server/openapi.ts: import http from 'http';
import { appRouter } from './routes/_app'
import { generateOpenApiDocument } from 'trpc-openapi';
import { createOpenApiHttpHandler } from 'trpc-openapi';
import { createContext } from './context';
export const openApiDocument = generateOpenApiDocument(appRouter, {
title: 'MyAPI',
version: '0.0.1',
baseUrl: 'http://localhost:3001/',
});
const server = http.createServer(createOpenApiHttpHandler({ router: appRouter, responseMeta: (data) => {
if (data && data.ctx && data.ctx.res) {
data.ctx.res.setHeader('Access-Control-Allow-Origin', '*');
data.ctx.res.setHeader('Access-Control-Request-Method', '*');
data.ctx.res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
data.ctx.res.setHeader('Access-Control-Allow-Headers', '*');
console.log(data.ctx.res);
}
}
, createContext }));
server.listen(3001); so when I hit /openapi including '$lib/server/openapi' will start a openapi server on a port e.g. 3001. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
thanks for help.
Beta Was this translation helpful? Give feedback.
All reactions