2025-06-05 04:43:00 +00:00
|
|
|
import express from 'express';
|
|
|
|
|
import cors from 'cors';
|
|
|
|
|
import dotenv from 'dotenv';
|
2025-08-09 19:49:15 +00:00
|
|
|
import userRouter from './services/user/index.js';
|
|
|
|
|
import departmentRouter from './services/department/index.js';
|
|
|
|
|
import pool from './services/postgres/postgresServices.js';
|
2025-06-05 04:43:00 +00:00
|
|
|
dotenv.config();
|
2025-06-23 21:55:42 +00:00
|
|
|
import { routes } from './router/routes.js';
|
2025-06-05 04:02:22 +00:00
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
|
|
|
|
|
|
const corsOptions = {
|
2025-06-14 17:28:29 +00:00
|
|
|
origin: [
|
|
|
|
|
"http://localhost:5173",
|
|
|
|
|
"https://shift-dev.code-catalyst.com",
|
|
|
|
|
"https://shift.code-catalyst.com"
|
|
|
|
|
]
|
2025-06-05 04:02:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
app.use(cors(corsOptions));
|
2025-06-23 21:55:42 +00:00
|
|
|
app.use(express.json({ limit: '10mb' }));
|
|
|
|
|
app.use('/api', routes);
|
2025-06-05 04:02:22 +00:00
|
|
|
|
2025-06-23 21:55:42 +00:00
|
|
|
app.get('*route', (req, res) => {
|
|
|
|
|
res.send("Hello from ShiftSync");
|
2025-06-05 04:02:22 +00:00
|
|
|
});
|
|
|
|
|
|
2025-08-09 19:49:15 +00:00
|
|
|
app.use(express.json());
|
|
|
|
|
|
|
|
|
|
const apiRouter = express.Router();
|
|
|
|
|
|
|
|
|
|
apiRouter.use('/user', userRouter);
|
|
|
|
|
apiRouter.use('/department', departmentRouter);
|
|
|
|
|
|
|
|
|
|
app.get("/api", (req, res) => {
|
|
|
|
|
res.json('Welcome to Shift Sync API');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.use('/api', apiRouter);
|
|
|
|
|
|
|
|
|
|
app.get('/db-health', async (req, res) => {
|
|
|
|
|
try {
|
|
|
|
|
console.log('in');
|
|
|
|
|
const result = await pool.query('SELECT NOW()');
|
|
|
|
|
console.log('after result');
|
|
|
|
|
res.json({ connected: true, time: result.rows[0].now });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
res.status(500).json({ connected: false, error: err.message });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-06-05 04:02:22 +00:00
|
|
|
app.listen(5172, () => {
|
|
|
|
|
console.log('Server Started on port 5172');
|
|
|
|
|
});
|