mirror of
https://github.com/nestriness/nestri.git
synced 2026-08-01 17:34:15 +03:00
feat: Add some openapi spec stuff
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@nestri/function",
|
"name": "@nestri/function",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
"version":"0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "catalog:",
|
"@cloudflare/workers-types": "catalog:",
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { auth } from "./utils/auth";
|
import { auth } from "./utils/auth";
|
||||||
import { logger } from "hono/logger";
|
import { logger } from "hono/logger";
|
||||||
|
import { openAPIRouteHandler } from "hono-openapi";
|
||||||
import { Log } from "@nestri/core/utils/log";
|
import { Log } from "@nestri/core/utils/log";
|
||||||
import { HTTPException } from "hono/http-exception";
|
import { HTTPException } from "hono/http-exception";
|
||||||
import { VisibleError, ErrorCodes } from "@nestri/core/error";
|
import { VisibleError, ErrorCodes } from "@nestri/core/error";
|
||||||
|
import packageJson from "../../package.json" assert { type: "json" };
|
||||||
|
|
||||||
const log = Log.create({ service: "api" });
|
const log = Log.create({ service: "api" });
|
||||||
|
|
||||||
@@ -16,7 +18,11 @@ app
|
|||||||
})
|
})
|
||||||
.use(auth);
|
.use(auth);
|
||||||
|
|
||||||
app.onError((error, c) => {
|
export const routes = app
|
||||||
|
.get("/", async (c) => {
|
||||||
|
return c.text("ok");
|
||||||
|
})
|
||||||
|
.onError((error, c) => {
|
||||||
// Handle our custom VisibleError
|
// Handle our custom VisibleError
|
||||||
if (error instanceof VisibleError) {
|
if (error instanceof VisibleError) {
|
||||||
return c.json(error.toResponse(), error.statusCode());
|
return c.json(error.toResponse(), error.statusCode());
|
||||||
@@ -45,4 +51,39 @@ app.onError((error, c) => {
|
|||||||
},
|
},
|
||||||
500,
|
500,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get(
|
||||||
|
"/doc",
|
||||||
|
openAPIRouteHandler(routes, {
|
||||||
|
documentation: {
|
||||||
|
info: {
|
||||||
|
title: "Nestri API",
|
||||||
|
termsOfService: "https://nestri.io/terms",
|
||||||
|
description:
|
||||||
|
"The Nestri API gives you the power deploy and stream games/apps in the cloud. Run on our GPUs or bring your own.",
|
||||||
|
version: packageJson.version ?? "1.0.0",
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
securitySchemes: {
|
||||||
|
Bearer: {
|
||||||
|
type: "http",
|
||||||
|
scheme: "bearer",
|
||||||
|
bearerFormat: "JWT",
|
||||||
|
},
|
||||||
|
MemberID: {
|
||||||
|
type: "apiKey",
|
||||||
|
description: "The member ID to use for this query",
|
||||||
|
in: "header",
|
||||||
|
name: "x-nestri-member",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
security: [{ Bearer: [], MemberID: [] }],
|
||||||
|
servers: [
|
||||||
|
{ description: "Production", url: "https://api.nestri.io" },
|
||||||
|
{ description: "Sandbox", url: "https://api.dev.nestri.io" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user