Files
book-test/api/src/index.ts
T
chris a7524412f0
CI/CD Pipeline / test (push) Failing after 2m38s
CI/CD Pipeline / deploy-internal (push) Has been skipped
Add web front-end and fix API issues
2026-08-28 21:47:05 -04:00

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}`);
});