| import express from 'express'; |
| import helmet from 'helmet'; |
| import cors from 'cors'; |
| import { createClient } from 'redis'; |
| import { Queue } from 'bullmq'; |
| import { config } from './config'; |
| import { authRouter } from './modules/auth/routes'; |
| import { jobsRouter } from './modules/jobs/routes'; |
| import { candidatesRouter } from './modules/candidates/routes'; |
| import { tasksRouter } from './modules/tasks/routes'; |
| import { errorHandler } from './shared/middleware/errorHandler'; |
|
|
| const app = express(); |
|
|
| export const redisClient = createClient({ url: config.REDIS_URL }); |
| export const resumeQueue = new Queue('resume-parsing', { |
| connection: redisClient.duplicate(), |
| }); |
|
|
| app.use(helmet()); |
| app.use(cors({ origin: process.env.NODE_ENV === 'production' ? [/\.vercel\.app$/] : true, credentials: true })); |
| app.use(express.json({ limit: '10mb' })); |
|
|
| app.get('/health', (_req, res) => res.json({ status: 'ok', timestamp: new Date().toISOString() })); |
|
|
| app.use('/api/v1/auth', authRouter); |
| app.use('/api/v1/jobs', jobsRouter); |
| app.use('/api/v1/candidates', candidatesRouter); |
| app.use('/api/v1/tasks', tasksRouter); |
|
|
| app.use(errorHandler); |
|
|
| async function start() { |
| await redisClient.connect(); |
| console.log('Redis connected'); |
|
|
| app.listen(config.PORT, () => { |
| console.log(`Core API running on http://localhost:${config.PORT}`); |
| }); |
| } |
|
|
| start().catch(console.error); |
|
|