From f63d9fd467b0aef51f3f9929cb32b585d2b90288 Mon Sep 17 00:00:00 2001 From: brblacky Date: Fri, 12 Apr 2024 23:37:29 +0530 Subject: [PATCH] Refactor API files and configurations --- api/.gitignore | 45 ----------------------------- api/package.json | 28 ------------------ api/prisma/schema.prisma | 33 ---------------------- api/process.json | 12 -------- api/src/index.ts | 61 ---------------------------------------- api/tsconfig.json | 18 ------------ api/vitest.config.ts | 11 -------- api/wrangler.toml | 8 ------ 8 files changed, 216 deletions(-) delete mode 100644 api/.gitignore delete mode 100644 api/package.json delete mode 100644 api/prisma/schema.prisma delete mode 100644 api/process.json delete mode 100644 api/src/index.ts delete mode 100644 api/tsconfig.json delete mode 100644 api/vitest.config.ts delete mode 100644 api/wrangler.toml diff --git a/api/.gitignore b/api/.gitignore deleted file mode 100644 index 9093358..0000000 --- a/api/.gitignore +++ /dev/null @@ -1,45 +0,0 @@ -# compiled output -/dist -/node_modules - -# Logs -logs -*.log -npm-debug.log* -pnpm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# OS -.DS_Store - -# Tests -/coverage -/.nyc_output - -# IDEs and editors -/.idea -.project -.classpath -.c9/ -*.launch -.settings/ -*.sublime-workspace - -# IDE - VSCode -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json - -# prisma -/prisma/migrations - -# build output -/build - -.env - -package-lock.json \ No newline at end of file diff --git a/api/package.json b/api/package.json deleted file mode 100644 index 6ad5876..0000000 --- a/api/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "lavalink-api", - "version": "1.0.0", - "description": "lavalink-api for list of lavalink nodes in cloudflare workers", - "main": "index.js", - "devDependencies": { - "@cloudflare/vitest-pool-workers": "0.1.17", - "@cloudflare/workers-types": "4.20240405.0", - "@types/node": "^20.12.5", - "prisma": "5.12.1", - "typescript": "5.4.4", - "vitest": "1.4.0", - "wrangler": "3.48.0" - }, - "dependencies": { - "@prisma/client": "5.12.1", - "@prisma/extension-accelerate": "^1.0.0" - }, - "scripts": { - "deploy": "wrangler deploy -e production", - "dev": "wrangler dev", - "start": "wrangler dev", - "test": "vitest" - }, - "keywords": [], - "author": "", - "license": "ISC" -} \ No newline at end of file diff --git a/api/prisma/schema.prisma b/api/prisma/schema.prisma deleted file mode 100644 index 4d43e22..0000000 --- a/api/prisma/schema.prisma +++ /dev/null @@ -1,33 +0,0 @@ - -generator client { - provider = "prisma-client-js" - previewFeatures = ["driverAdapters"] -} - -datasource db { - provider = "postgresql" - url = env("DATABASE_URL") - directUrl = env("DIRECT_DATABASE_URL") -} - -model Node { - authorId String - host String - identifier String @unique - password String - port Int - restVersion String - secure Boolean - isConnected Boolean @default(false) - info Json? - author Json? - memory String? - connections String? - systemLoad String? - cpuCores Int? - uptime String? - cpu String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -} - diff --git a/api/process.json b/api/process.json deleted file mode 100644 index 72d27d9..0000000 --- a/api/process.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "apps": [ - { - "name": "lava-list-api", - "script": "build/index.js", - "node_args": [ - "--enable-source-maps" - ], - "restart_delay": 10000 - } - ] -} \ No newline at end of file diff --git a/api/src/index.ts b/api/src/index.ts deleted file mode 100644 index 2bd898b..0000000 --- a/api/src/index.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { PrismaClient } from '@prisma/client/edge' -import { withAccelerate } from '@prisma/extension-accelerate' - -export interface Env { - DATABASE_URL: string; -} - - -export default { - fetch: async (request: Request, env: Env, ctx: ExecutionContext) => { - try { - - const prisma = new PrismaClient({ - datasourceUrl: env.DATABASE_URL - }).$extends(withAccelerate()); - const url = new URL(request.url); - - if (url.pathname === "/") { - return new Response("Welcome to Lavalink status api", { - headers: { - "Content-Type": "text/plain" - } - }); - } else if (url.pathname === "/ssl-nodes" || url.pathname === "/non-ssl-nodes") { - - const nodes = await prisma.node.findMany({ - where: { - secure: url.pathname === "/ssl-nodes" ? true : false - } - }); - if (nodes.length === 0) { - return new Response("Not Found", { - status: 404, - headers: { - "Content-Type": "text/plain" - } - }); - } - return new Response(JSON.stringify(nodes), { - headers: { - "Content-Type": "application/json" - } - }); - } else { - return new Response("Not Found", { - status: 404, - headers: { - "Content-Type": "text/plain" - } - }); - } - } catch (error: any) { - return new Response(error.message || "Internal Server Error", { - status: 500, - headers: { - "Content-Type": "text/plain" - } - }); - } - } -} \ No newline at end of file diff --git a/api/tsconfig.json b/api/tsconfig.json deleted file mode 100644 index e4ef89f..0000000 --- a/api/tsconfig.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "compilerOptions": { - "outDir": "./dist", - "module": "commonjs", - "target": "esnext", - "lib": ["webworker", "dom", "es6"], - "alwaysStrict": true, - "strict": true, - "noImplicitAny": false, - "preserveConstEnums": true, - "moduleResolution": "node", - "sourceMap": true, - "esModuleInterop": true, - "types": ["@cloudflare/workers-types", "@types/node"] - }, - "include": ["src"], - "exclude": ["node_modules", "dist", "test"] -} \ No newline at end of file diff --git a/api/vitest.config.ts b/api/vitest.config.ts deleted file mode 100644 index fd9661e..0000000 --- a/api/vitest.config.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config"; - -export default defineWorkersConfig({ - test: { - poolOptions: { - workers: { - wrangler: { configPath: "./wrangler.toml" }, - }, - }, - }, -}); \ No newline at end of file diff --git a/api/wrangler.toml b/api/wrangler.toml deleted file mode 100644 index 7444614..0000000 --- a/api/wrangler.toml +++ /dev/null @@ -1,8 +0,0 @@ -name = "cloudflare-worker-api" -account_id = "" -main = "src/index.ts" -compatibility_date = "2024-04-07" -compatibility_flags = ["nodejs_compat"] - - -[env.production.vars]