Feature/api paramyxrx #25
2 changed files with 27 additions and 1 deletions
21
api/middleware/auth.js
Normal file
21
api/middleware/auth.js
Normal 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();
|
||||
};
|
||||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in a new issue