creating contenerization
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { Elysia } from "elysia";
|
||||
import { routes } from "./routes";
|
||||
|
||||
const app = new Elysia().use(routes).listen(3200);
|
||||
const app = new Elysia().use(routes).listen(process.env.PORT || 3000);
|
||||
|
||||
console.log(
|
||||
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
|
||||
|
||||
32
src/routes.legacy.ts
Normal file
32
src/routes.legacy.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import Elysia from "elysia";
|
||||
import { pathToFileURL } from "bun";
|
||||
import { readdirSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
const routes = new Elysia();
|
||||
|
||||
const modulesPath = join(__dirname, "./modules");
|
||||
|
||||
for (const folder of readdirSync(modulesPath, { withFileTypes: true })) {
|
||||
if (folder.isDirectory()) {
|
||||
const moduleIndex = join(modulesPath, folder.name, "index.ts");
|
||||
|
||||
try {
|
||||
const module = await import(pathToFileURL(moduleIndex).href);
|
||||
|
||||
const mod = Object.values(module).find(
|
||||
(m): m is Elysia => m instanceof Elysia
|
||||
);
|
||||
|
||||
if (mod) {
|
||||
routes.use(mod);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Module ${folder.name} not found. Please check the module path or name: ${error}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { routes };
|
||||
@ -1,32 +1,12 @@
|
||||
|
||||
import Elysia from "elysia";
|
||||
import { pathToFileURL } from "bun";
|
||||
import { readdirSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
const routes = new Elysia();
|
||||
|
||||
const modulesPath = join(__dirname, "./modules");
|
||||
|
||||
for (const folder of readdirSync(modulesPath, { withFileTypes: true })) {
|
||||
if (folder.isDirectory()) {
|
||||
const moduleIndex = join(modulesPath, folder.name, "index.ts");
|
||||
|
||||
try {
|
||||
const module = await import(pathToFileURL(moduleIndex).href);
|
||||
|
||||
const mod = Object.values(module).find(
|
||||
(m): m is Elysia => m instanceof Elysia
|
||||
);
|
||||
|
||||
if (mod) {
|
||||
routes.use(mod);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Module ${folder.name} not found. Please check the module path or name: ${error}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
import {authModule} from './modules/auth';
|
||||
import {userModule} from './modules/user';
|
||||
import {userRoleModule} from './modules/userRole';
|
||||
import {userSessionModule} from './modules/userSession';
|
||||
const routes = new Elysia()
|
||||
.use(authModule)
|
||||
.use(userModule)
|
||||
.use(userRoleModule)
|
||||
.use(userSessionModule);
|
||||
export { routes };
|
||||
|
||||
Reference in New Issue
Block a user