2025-06-05 04:43:00 +00:00
|
|
|
import express from 'express';
|
|
|
|
|
import cors from 'cors';
|
|
|
|
|
import dotenv from 'dotenv';
|
2026-01-18 03:39:32 +00:00
|
|
|
import { medicationRouter } from './services/medications/index.js';
|
2026-01-18 06:26:01 +00:00
|
|
|
import { shiftsRouter } from './services/shifts/index.js';
|
2026-01-18 03:39:32 +00:00
|
|
|
import { shiftRunQuery } from './services/shiftConnection.js';
|
2026-01-18 06:26:01 +00:00
|
|
|
import { validateMedicationApiKey, validateShiftSyncApiKey } from './middleware/auth.js';
|
2025-06-05 04:43:00 +00:00
|
|
|
dotenv.config();
|
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));
|
2026-01-18 03:39:32 +00:00
|
|
|
app.use(express.json({ limit: '10mb' }));
|
|
|
|
|
|
|
|
|
|
app.use(express.json());
|
|
|
|
|
|
|
|
|
|
const apiRouter = express.Router();
|
|
|
|
|
|
2026-01-18 06:26:01 +00:00
|
|
|
// ParamyxRx Router (/api/medication)
|
|
|
|
|
apiRouter.use('/medication', validateMedicationApiKey, medicationRouter);
|
|
|
|
|
|
|
|
|
|
// ShiftSync Router (/api/shifts)
|
|
|
|
|
apiRouter.use('/shifts', validateShiftSyncApiKey, shiftsRouter);
|
2025-06-05 04:02:22 +00:00
|
|
|
|
|
|
|
|
app.get("/api", (req, res) => {
|
2026-01-18 03:39:32 +00:00
|
|
|
res.json('Welcome to Shift Sync API');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.use('/api', apiRouter);
|
|
|
|
|
|
2026-01-18 06:26:01 +00:00
|
|
|
app.get('/api/db-health', async (req, res) => {
|
2026-01-18 03:39:32 +00:00
|
|
|
try {
|
|
|
|
|
const result = await shiftRunQuery('SELECT NOW()');
|
|
|
|
|
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
|
|
|
});
|
2026-01-18 22:20:55 +00:00
|
|
|
app.get('/api/version', async (req, res) => {
|
|
|
|
|
try {
|
2026-01-19 22:40:15 +00:00
|
|
|
res.json('1.0.5');
|
2026-01-18 22:20:55 +00:00
|
|
|
} 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');
|
|
|
|
|
});
|