Initial commit
This commit is contained in:
37
src/index.ts
Normal file
37
src/index.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Elysia } from "elysia";
|
||||
import { cors } from "@elysiajs/cors"
|
||||
import { jsonResponse } from "./lib/util";
|
||||
import { drizzle } from 'drizzle-orm/mysql2';
|
||||
import mysql from 'mysql2/promise';
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
import { handler as launcherVersionsHandler } from "./routes/launcher/versions";
|
||||
import { handler as launcherLatestHandler } from "./routes/launcher/latest";
|
||||
import { handler as launcherLoaderLatestHandler } from "./routes/launcher/loader/latest";
|
||||
import { handler as launcherLoaderUpdateDataHandler } from "./routes/launcher/loader/update-data";
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const connection = await mysql.createConnection({
|
||||
host: process.env.DB_HOST ?? 'localhost',
|
||||
port: Number(process.env.DB_PORT) || 3306,
|
||||
user: process.env.DB_USER ?? '',
|
||||
password: process.env.DB_PASS ?? '',
|
||||
database: process.env.DB_NAME ?? ''
|
||||
});
|
||||
|
||||
const db = drizzle(connection);
|
||||
|
||||
const app = new Elysia()
|
||||
.use(cors({
|
||||
origin: "*",
|
||||
methods: ["POST", "GET"]
|
||||
}))
|
||||
|
||||
app.get("/launcher/versions", (context) => launcherVersionsHandler(context, db))
|
||||
app.get("/launcher/latest", launcherLatestHandler)
|
||||
app.get("/launcher/loader/latest", launcherLoaderLatestHandler)
|
||||
app.get("/launcher/loader/update-data", (context) => launcherLoaderUpdateDataHandler(context, db))
|
||||
app.all("*", () => jsonResponse({ message: "No endpoint found (are you using the correct request method?)" }, 404))
|
||||
|
||||
app.listen(3342)
|
||||
Reference in New Issue
Block a user