Feature/api paramyxrx #25

Merged
mattdimegs merged 10 commits from feature/api-paramyxrx into main 2026-01-18 06:26:01 +00:00
2 changed files with 27 additions and 1 deletions
Showing only changes of commit aead6a8358 - Show all commits

21
api/middleware/auth.js Normal file
View file

@ -0,0 +1,21 @@
export const validateMedicationApiKey = (req, res, next) => {
const authHeader = req.headers['authorization'];
const token = authHeader && authHeader.split(' ')[1];
if (!token || token !== process.env.MEDICATION_API_KEY) {
return res.status(401).json({ error: 'Unauthorized - Invalid API Key' });
}
next();
};
export const validateShiftSyncApiKey = (req, res, next) => {
const authHeader = req.headers['authorization'];
const token = authHeader && authHeader.split(' ')[1];
if (!token || token !== process.env.SHIFTSYNC_API_KEY) {
return res.status(401).json({ error: 'Unauthorized - Invalid API Key' });
}
next();
};

View file

@ -3,6 +3,7 @@ import cors from 'cors';
import dotenv from 'dotenv';
import { medicationRouter } from './services/medications/index.js';
import { shiftRunQuery } from './services/shiftConnection.js';
import { validateMedicationApiKey, validateShiftSyncApiKey } from './middleware/auth.js';
dotenv.config();
const app = express();
@ -22,7 +23,11 @@ app.use(express.json());
const apiRouter = express.Router();
apiRouter.use('/medication', medicationRouter);
// ParamyxRx Router (/api/medication)
apiRouter.use('/medication', validateMedicationApiKey, medicationRouter);
// ShiftSync Router (/api/shifts)
apiRouter.use('/shifts', validateShiftSyncApiKey, shiftsRouter);
app.get("/api", (req, res) => {
res.json('Welcome to Shift Sync API');