mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-11 00:05:36 +02:00
feat: Start working on Auth
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actor-core/bun": "^0.8.0",
|
"@actor-core/bun": "^0.8.0",
|
||||||
"@actor-core/file-system": "^0.8.0",
|
"@actor-core/file-system": "^0.8.0",
|
||||||
|
"@openauthjs/openauth": "catalog:",
|
||||||
"@aws-sdk/client-lambda": "^3.821.0",
|
"@aws-sdk/client-lambda": "^3.821.0",
|
||||||
"@aws-sdk/client-s3": "^3.806.0",
|
"@aws-sdk/client-s3": "^3.806.0",
|
||||||
"@aws-sdk/client-sqs": "^3.806.0",
|
"@aws-sdk/client-sqs": "^3.806.0",
|
||||||
@@ -27,4 +28,4 @@
|
|||||||
"steamcommunity": "^3.48.6",
|
"steamcommunity": "^3.48.6",
|
||||||
"steamid": "^2.1.0"
|
"steamid": "^2.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,88 +9,88 @@ import { AccountApi } from "./account";
|
|||||||
import { openAPISpecs } from "hono-openapi";
|
import { openAPISpecs } from "hono-openapi";
|
||||||
import { patchLogger } from "../utils/patch-logger";
|
import { patchLogger } from "../utils/patch-logger";
|
||||||
import { HTTPException } from "hono/http-exception";
|
import { HTTPException } from "hono/http-exception";
|
||||||
import { handle, streamHandle } from "hono/aws-lambda";
|
|
||||||
import { ErrorCodes, VisibleError } from "@nestri/core/error";
|
import { ErrorCodes, VisibleError } from "@nestri/core/error";
|
||||||
|
|
||||||
patchLogger();
|
patchLogger();
|
||||||
|
|
||||||
export const app = new Hono();
|
export const app = new Hono();
|
||||||
app
|
app
|
||||||
.use(logger())
|
.use(logger())
|
||||||
.use(async (c, next) => {
|
.use(async (c, next) => {
|
||||||
c.header("Cache-Control", "no-store");
|
c.header("Cache-Control", "no-store");
|
||||||
return next();
|
return next();
|
||||||
})
|
})
|
||||||
.use(auth)
|
.use(auth);
|
||||||
|
|
||||||
const routes = app
|
const routes = app
|
||||||
.get("/", (c) => c.text("Hello World!"))
|
.get("/", (c) => c.text("Hello World!"))
|
||||||
.route("/games", GameApi.route)
|
.route("/games", GameApi.route)
|
||||||
.route("/steam", SteamApi.route)
|
.route("/steam", SteamApi.route)
|
||||||
.route("/friends", FriendApi.route)
|
.route("/friends", FriendApi.route)
|
||||||
.route("/account", AccountApi.route)
|
.route("/account", AccountApi.route)
|
||||||
.onError((error, c) => {
|
.onError((error, c) => {
|
||||||
if (error instanceof VisibleError) {
|
if (error instanceof VisibleError) {
|
||||||
console.error("api error:", error);
|
console.error("api error:", error);
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
return c.json(error.toResponse(), error.statusCode());
|
return c.json(error.toResponse(), error.statusCode());
|
||||||
}
|
}
|
||||||
// Handle HTTP exceptions
|
// Handle HTTP exceptions
|
||||||
if (error instanceof HTTPException) {
|
if (error instanceof HTTPException) {
|
||||||
console.error("http error:", error);
|
console.error("http error:", error);
|
||||||
return c.json(
|
return c.json(
|
||||||
{
|
{
|
||||||
type: "validation",
|
type: "validation",
|
||||||
code: ErrorCodes.Validation.INVALID_PARAMETER,
|
code: ErrorCodes.Validation.INVALID_PARAMETER,
|
||||||
message: "Invalid request",
|
message: "Invalid request",
|
||||||
},
|
},
|
||||||
error.status,
|
error.status,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
console.error("unhandled error:", error);
|
console.error("unhandled error:", error);
|
||||||
return c.json(
|
return c.json(
|
||||||
{
|
{
|
||||||
type: "internal",
|
type: "internal",
|
||||||
code: ErrorCodes.Server.INTERNAL_ERROR,
|
code: ErrorCodes.Server.INTERNAL_ERROR,
|
||||||
message: "Internal server error",
|
message: "Internal server error",
|
||||||
},
|
},
|
||||||
500,
|
500,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get(
|
app.get(
|
||||||
"/doc",
|
"/doc",
|
||||||
openAPISpecs(routes, {
|
openAPISpecs(routes, {
|
||||||
documentation: {
|
documentation: {
|
||||||
info: {
|
info: {
|
||||||
title: "Nestri API",
|
title: "Nestri API",
|
||||||
description: "The Nestri API gives you the power to run your own customized cloud gaming platform.",
|
description:
|
||||||
version: "0.0.1",
|
"The Nestri API gives you the power to run your own customized cloud gaming platform.",
|
||||||
},
|
version: "0.0.1",
|
||||||
components: {
|
},
|
||||||
securitySchemes: {
|
components: {
|
||||||
Bearer: {
|
securitySchemes: {
|
||||||
type: "http",
|
Bearer: {
|
||||||
scheme: "bearer",
|
type: "http",
|
||||||
bearerFormat: "JWT",
|
scheme: "bearer",
|
||||||
},
|
bearerFormat: "JWT",
|
||||||
TeamID: {
|
},
|
||||||
type: "apiKey",
|
SteamID: {
|
||||||
description: "The steam ID to use for this query",
|
type: "apiKey",
|
||||||
in: "header",
|
description: "The steam ID to use for this query",
|
||||||
name: "x-nestri-steam"
|
in: "header",
|
||||||
},
|
name: "x-nestri-steam",
|
||||||
},
|
},
|
||||||
},
|
|
||||||
security: [{ Bearer: [], TeamID: [] }],
|
|
||||||
servers: [
|
|
||||||
{ description: "Production", url: "https://api.nestri.io" },
|
|
||||||
{ description: "Sandbox", url: "https://api.dev.nestri.io" },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
|
security: [{ Bearer: [], TeamID: [] }],
|
||||||
|
servers: [
|
||||||
|
{ description: "Production", url: "https://api.nestri.io" },
|
||||||
|
{ description: "Sandbox", url: "https://api.dev.nestri.io" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
export type Routes = typeof routes;
|
export type Routes = typeof routes;
|
||||||
|
|
||||||
export const handler = process.env.SST_LIVE ? handle(app) : streamHandle(app);
|
export default app;
|
||||||
|
|||||||
20
package.json
20
package.json
@@ -17,21 +17,23 @@
|
|||||||
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
|
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
|
||||||
"sso": "aws sso login --sso-session=nestri --no-browser --use-device-code"
|
"sso": "aws sso login --sso-session=nestri --no-browser --use-device-code"
|
||||||
},
|
},
|
||||||
"overrides": {
|
|
||||||
"@openauthjs/openauth": "0.4.3",
|
|
||||||
"steam-session": "1.9.3"
|
|
||||||
},
|
|
||||||
"trustedDependencies": [
|
"trustedDependencies": [
|
||||||
"core-js-pure",
|
"core-js-pure",
|
||||||
"esbuild",
|
"esbuild",
|
||||||
"protobufjs",
|
"protobufjs",
|
||||||
"workerd"
|
"workerd"
|
||||||
],
|
],
|
||||||
"workspaces": [
|
"workspaces": {
|
||||||
"apps/*",
|
"packages": [
|
||||||
"packages/*",
|
"apps/*",
|
||||||
"cloud/packages/*"
|
"packages/*",
|
||||||
],
|
"cloud/packages/*"
|
||||||
|
],
|
||||||
|
"catalog": {
|
||||||
|
"@openauthjs/openauth": "0.0.0-20250322224806",
|
||||||
|
"steam-session": "1.9.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"sst": "^3.17.13"
|
"sst": "^3.17.13"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user