Add Elysia API scaffold
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
export const env = {
|
||||
port: Number(Bun.env.API_PORT ?? 3000),
|
||||
databaseUrl: Bun.env.DATABASE_URL,
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import postgres from 'postgres';
|
||||
import { env } from '../config/env';
|
||||
import * as schema from './schema';
|
||||
|
||||
export function createDbClient() {
|
||||
if (!env.databaseUrl) {
|
||||
throw new Error('DATABASE_URL is required to create a database client');
|
||||
}
|
||||
|
||||
const client = postgres(env.databaseUrl);
|
||||
return drizzle(client, { schema });
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { pgTable, timestamp, uuid, varchar } from 'drizzle-orm/pg-core';
|
||||
|
||||
export const appEvents = pgTable('app_events', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
name: varchar('name', { length: 120 }).notNull(),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Elysia } from 'elysia';
|
||||
import { env } from './config/env';
|
||||
import { healthRoutes } from './routes/health';
|
||||
import { statusRoutes } from './routes/status';
|
||||
|
||||
const app = new Elysia().use(healthRoutes).use(statusRoutes).listen(env.port);
|
||||
|
||||
console.log(`ZeaVis Edu API running at http://${app.server?.hostname}:${app.server?.port}`);
|
||||
|
||||
export type App = typeof app;
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Elysia } from 'elysia';
|
||||
|
||||
export const healthRoutes = new Elysia().get('/health', () => ({
|
||||
status: 'ok' as const,
|
||||
}));
|
||||
@@ -0,0 +1,6 @@
|
||||
import { createAppStatus } from '@zeavis/shared';
|
||||
import { Elysia } from 'elysia';
|
||||
|
||||
export const statusRoutes = new Elysia({ prefix: '/api/v1' }).get('/status', () =>
|
||||
createAppStatus(),
|
||||
);
|
||||
Reference in New Issue
Block a user