33 lines
1009 B
TypeScript
33 lines
1009 B
TypeScript
import express from 'express';
|
|
import { Pool } from 'pg';
|
|
import { CategoryRepository } from './category.repository.ts';
|
|
import { createCategoryRouter } from './category.router.ts';
|
|
import { join } from 'node:path';
|
|
import process from 'node:process';
|
|
|
|
try {
|
|
process.loadEnvFile(join(import.meta.dirname, '../.env'));
|
|
} catch (e) {
|
|
console.warn('⚠️ API Warning: Could not locate local .env file natively.');
|
|
}
|
|
|
|
const app = express();
|
|
const port = process.env.API_PORT || 8300;
|
|
|
|
// Initialize your database pool
|
|
const pool = new Pool({
|
|
connectionString: process.env.DATABASE_URL || process.env.INTERNAL_PROD_DB_URL
|
|
});
|
|
|
|
app.use(express.json());
|
|
|
|
// Inject the database pool into the repository layer
|
|
const categoryRepository = new CategoryRepository(pool);
|
|
|
|
// Attach your category endpoints to the Express app
|
|
app.use('/api/categories', createCategoryRouter(categoryRepository));
|
|
|
|
app.listen(port, () => {
|
|
console.log(`🚀 API workspace server running smoothly on http://localhost:${port}`);
|
|
});
|