Skip to content

Commit

Permalink
refactor: reorganize code
Browse files Browse the repository at this point in the history
  • Loading branch information
j1nxie committed Mar 7, 2024
1 parent 474e7ee commit 042c61d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 35 deletions.
11 changes: 0 additions & 11 deletions src/eventRoute.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/getStatus.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import eventRouter from "./eventRoute.js";
import statusRouter from "./statusRoute.js";
import eventRouter from "./routes/eventRoute.js";
import statusRouter from "./routes/statusRoute.js";
import cors from "@fastify/cors";
import * as dotenv from "dotenv";
import fastify from "fastify";
Expand Down
10 changes: 9 additions & 1 deletion src/getEvent.ts → src/routes/eventRoute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { JSDOM } from "jsdom";
import fetch from "node-fetch";
import type { FastifyInstance } from "fastify";

/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-call */
function eventRouter(fastify: FastifyInstance, options: any, done: any) {
fastify.get("/event", getEvent);
done();
}

const BASE_URL = "https://gamepress.gg/arknights/";

Expand Down Expand Up @@ -73,4 +81,4 @@ async function getEvent() {
}
}

export default getEvent;
export default eventRouter;
19 changes: 18 additions & 1 deletion src/statusRoute.ts → src/routes/statusRoute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import getStatus from "./getStatus.js";
import { VERSION_PRETTY } from "../constants/version.js";
import type { FastifyInstance } from "fastify";

/* eslint-disable @typescript-eslint/no-explicit-any */
Expand All @@ -9,3 +9,20 @@ function statusRouter(fastify: FastifyInstance, options: any, done: any) {
}

export default statusRouter;

function getStatus() {
try {
return {
success: true,
data: {
serverTime: Date.now(),
version: VERSION_PRETTY,
},
};
} catch (err) {
return {
success: false,
error: err,
};
}
}

0 comments on commit 042c61d

Please sign in to comment.