WIP
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import path from "path"
|
||||
import type { IUser } from "~/netcode/interfaces"
|
||||
|
||||
|
||||
enum HTTPMethods {
|
||||
GET = "GET",
|
||||
POST = "POST"
|
||||
}
|
||||
|
||||
|
||||
const Endpoints = {
|
||||
LOGIN: { url: "/login", method: HTTPMethods.POST, body: null }
|
||||
} as const
|
||||
|
||||
type ReturnTypes = {
|
||||
LOGIN: IUser
|
||||
}
|
||||
|
||||
|
||||
type EnpointsNames = keyof typeof Endpoints
|
||||
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
|
||||
export default async function api<T extends EnpointsNames>(target: T, body?: typeof Endpoints[T]["body"]): Promise<ReturnTypes[T]> {
|
||||
const data = await fetch(path.join(config.public.endpoint, Endpoints[target].url), {
|
||||
credentials: "same-origin",
|
||||
mode: "same-origin",
|
||||
method: Endpoints[target].method,
|
||||
body,
|
||||
})
|
||||
return await data.json() as ReturnTypes[T]
|
||||
}
|
||||
Reference in New Issue
Block a user