mirror of
https://github.com/CyberL1/dlinux-dashboard.git
synced 2025-06-28 16:19:43 -04:00
init
This commit is contained in:
33
src/index.ts
Normal file
33
src/index.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import "dotenv/config";
|
||||
import fastify from "fastify";
|
||||
import { readdirSync } from "fs";
|
||||
|
||||
const app = fastify();
|
||||
|
||||
const routes = readdirSync(`${import.meta.dirname}/routes`, {
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
for (let file of routes) {
|
||||
if (typeof file === "string") {
|
||||
if (!file.endsWith(".ts")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
file = file.replaceAll("\\", "/");
|
||||
|
||||
let route = `/${file.split(".").slice(0, -1).join(".")}`;
|
||||
route = route.replaceAll("_", ":");
|
||||
|
||||
const routePath = route.endsWith("/index") ? route.slice(0, -6) : route;
|
||||
console.log(`Loading route: ${routePath}`);
|
||||
|
||||
app.register((await import(`./routes/${file}`)).default, {
|
||||
prefix: routePath,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await app.listen({ port: Number(process.env.PORT), host: process.env.HOST });
|
||||
|
||||
console.log("App ready on", `http://${process.env.HOST}:${process.env.PORT}`);
|
7
src/routes/index.ts
Normal file
7
src/routes/index.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import type { FastifyInstance } from "fastify";
|
||||
|
||||
export default (fastify: FastifyInstance) => {
|
||||
fastify.get("/", () => {
|
||||
return { appName: "code-containers" };
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user