File size: 1,370 Bytes
90a2963
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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);