chore: prepare for migration to OpenAPI
This commit is contained in:
36
src/api/index.tsx
Normal file
36
src/api/index.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { cors } from "@elysiajs/cors";
|
||||
import { swagger } from "@elysiajs/swagger";
|
||||
import Elysia from "elysia";
|
||||
import { apiMiddleware } from "../middleware/apiMiddleware";
|
||||
import { auth } from "../utils/auth";
|
||||
import { apikey } from "./apikey";
|
||||
|
||||
const isProduction = process.env.NODE_ENV === "production";
|
||||
|
||||
const api = new Elysia({
|
||||
prefix: "/api",
|
||||
})
|
||||
.use(cors())
|
||||
.all("/auth/*", ({ request }) => auth.handler(request))
|
||||
.get("/session", async ({ request }) => {
|
||||
const data = await auth.api.getSession({ headers: request.headers });
|
||||
return { data };
|
||||
})
|
||||
.use(apiMiddleware)
|
||||
.use(apikey);
|
||||
|
||||
if (!isProduction) {
|
||||
api.use(
|
||||
swagger({
|
||||
path: "/docs",
|
||||
documentation: {
|
||||
info: {
|
||||
title: "Bun + React API",
|
||||
version: "1.0.0",
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export default api;
|
||||
Reference in New Issue
Block a user